[英]how to submit the single form and use two submit button one button click then validate
<form>
<input type="submit" name="submit" id="formSubmit" value="SAVE FOR NOW" />
<input type="submit" name="submitAndConfirm" id="submitAndConfirm" value="CONFIRM AND UPLOAD TO SERVER" />
</form>
$(document).ready(function(){
$('#addPat').submit();
$('#submitAndConfirm').click(function(){
$('#addPat').validate({
rules:{
iscosId:{required:true},
pat_id:{required:true},
admissionDate:{required:true},
dischargePlace:{required:true}
},messages:{
iscosId:"Please reload the Page",
pat_id:"This field cannot be empty",
admissionDate:"This field cannot be empty",
dischargePlace:"This field cannot be empty"
}
});
});
});
What I want is; 我想要的是 when I submit the formSubmit
button I want form to not validate, but when I click submitAndConfirm button I want validate the form to be validated. 当我提交formSubmit
按钮时,我希望表单不通过验证,但是当我单击SubmitAndConfirm按钮时,我要对表单进行验证。
<script>
$(document).ready(function(){
...
});
</script>
Anyway, I would check it with php. 无论如何,我会用php检查它。
<?php
if (isSet($_POST['submit'])) {
if ($_POST['submit'] == "SAVE FOR NOW") {
//Your PHP testing & action code
} else { //or elseif ($_POST['submit'] == "CONFIRM AND UPLOAD TO SERVER"
//Your PHP code
};
};
?>
you can try this if I have completely understood the problem. 如果我已经完全理解问题,可以尝试一下。
when you want a form to be saved by a button and to be submitted by a another button, you have to use the attribute "formnovalidate" at the end of the buttton as bellow: 当您希望通过按钮保存表单并通过另一个按钮提交表单时,必须在按钮末尾使用“ formnovalidate”属性,如下所示:
<form action="" method="get" novalidate>
<p><label for="Text1" >First Name: </label><input name="Text1" type="text" required></p>
<p><label for="Text2">Last Name: </label><input name="Text2" type="text"></p>
<p><label for="Text3">Favorite Color: </label><input name="Text3" type="text"></p>
<p><input name="Submit1" type="submit" value="submit"> </p>
<p><input name="Save" type="button" value="save" formnovalidate> </p>
</form>
Try this 尝试这个
$(document).ready(function(){
$('#formSubmit').click(function(){
$('#addPat').submit();
});
$('#submitAndConfirm').click(function(){
$('#addPat').validate({
rules:{
iscosId:{required:true},
pat_id:{required:true},
admissionDate:{required:true},
dischargePlace:{required:true}
},messages:{
iscosId:"Please reload the Page",
pat_id:"This field cannot be empty",
admissionDate:"This field cannot be empty",
dischargePlace:"This field cannot be empty"
}
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.