admin管理员组文章数量:1319022
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
本文标签: phpjQuery validatesubmitting with submitHandlerStack Overflow
版权声明:本文标题:php - jQuery validate, submitting with submitHandler - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742051179a2418069.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论