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
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
Share Improve this question edited Jun 2, 2012 at 15:26 user2428118 8,1244 gold badges46 silver badges73 bronze badges asked Jun 2, 2012 at 10:42 iffiff 1926 silver badges14 bronze badges 1-
What kind of logging have you done? Have you checked the request in Firebug/Developer tools to see if the data is actually getting sent? Try
$('#myform').serialize()
,this
may not be referring to the form inside that function. – Christian Commented Jun 2, 2012 at 10:44
3 Answers
Reset to default 4I 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()
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');
},
$("#form_id").trigger('submit');
try this