如何提交单个表单并使用两个提交按钮单击一下按钮然后验证

时间:2015-11-19 10:51:40

标签: javascript php jquery mysql forms

<form>
    <input type="submit" name="submit" id="formSubmit" value="SAVE FOR NOW" />
    &nbsp;&nbsp;&nbsp;
    <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"

            }
        });
    });
});

我想要的是;当我提交formSubmit按钮时,我希望表单不验证,但是当我单击submitAndConfirm按钮时,我想验证要验证的表单。

3 个答案:

答案 0 :(得分:0)

<script>
$(document).ready(function(){
...
});
</script>

无论如何,我会用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 
  };
};
?>

答案 1 :(得分:0)

如果我完全理解了这个问题,你可以试试这个。

如果您希望通过按钮保存表单并通过其他按钮提交,则必须使用属性&#34; formnovalidate&#34;在buttton的尽头,如下:

<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">&nbsp;</p>
    <p><input name="Save" type="button" value="save" formnovalidate>&nbsp;</p>
</form>

答案 2 :(得分:0)

试试这个

$(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"

    }
});
});

});