I have a strange problem that is driving me crazy! I'd like to submit a HTML form by ajax using jquery-form version 3.46.0 and then get the POST data on server, but my Submit button's name won't show up in the POST data! Maybe there's something wrong with this lib?
This my code:
<form id="form" action="test.php" method="post">
<input name="email" type="email" placeholder="Email" required>
<!-- And yes! I didn't use an input with type submit because
I need my button to have some HTML content and applied css styles to them. -->
<button id="submit" type="submit" name="myFormName">
<span class="label">Submit</span>
</button>
</form>
<div id="formResult" style="display: block; margin: 20px 0; padding: 10px; background-color: #fbe6e6;" role="alert"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="//oss.maxcdn.com/jquery.form/3.50/jquery.form.min.js"></script>
<script>
jQuery(document).ready(function($) {
$('#submit').on('click', function(e) {
e.preventDefault();
$('#form').ajaxSubmit({
clearForm: true,
target: '#formResult',
success: function() {
// do sth
},
error: function() {
// do sth
}
});
});
});
</script>
And this is the test.php file:
<?php
var_dump($_POST);
I need the name of my Submit button appear in POST data on server as expected... But it doesn't! Does anybody have any idea?