Reputation: 192
I have an HTML-form
<form method="POST" action="" name="myform" id="myform">
<input type="text" name="email" id="email" />
<input type="supmit" name="submit" id="submit" value="submit" />
</form>
And a code of jQuery:
$(document).ready(function(){
var validator = $("#myform").validate({
ignore: ".ignore",
rules: {...},
messages: {...},
submitHandler: function(form) {
$.post('usr.php?resetpw', $(this).serialize(), function (data, textStatus) {
form.submit();
alert(data.inf);
},'json');
},
});
and also PHP-code usr.php that doesn't get $_POST-variables (isset($_POST['email'])
= false
)
if(isset($_GET['resetpw'])) {
$loggingData = array(
'inf' => utf8_encode("Your email address is: ".$_POST['email']),
'errorEmail' => '',
'mailExists' => '',
'success' => '',
);
}
echo json_encode($loggingData);
What is a correct code that post variables reached to PHP?
Thank you
Upvotes: 2
Views: 7593
Reputation: 13461
I just checked the source of validate
plugin from here http://jquery.bassistance.de/validate/jquery.validate.js
and it's calling submitHandler
like this
validator.settings.submitHandler.call( validator, validator.currentForm );
Which means this
will refer to the validator object
not the form
, so use the form
argument to refer to the form and serialize it's fields like this
$(form).serialize()
Upvotes: 4
Reputation: 3535
Serialize form
not this
.
so submithandler will looks like below..
submitHandler: function(form) {
$.post('usr.php?resetpw', $(form).serialize(), function (data, textStatus) {
form.submit();
alert(data.inf);
},'json');
},
Upvotes: 2