jQuery验证插件多个提交在Safari中不起作用

时间:2018-08-24 09:11:16

标签: javascript jquery validation

我正在使用Jquery验证插件来验证表单。 我想避免多次提交,所以我禁用了Submithandler中的按钮。 我已经读过我不应该在Submithandler中使用form.submit(),但是表单不会被提交。

所以最后我得到了可以使用的代码,该按钮被禁用,表单被提交。但它在Mac上的Safari中不起作用。 (在Chrome浏览器中可以正常工作) 我应该改变什么?

$(document).ready(function () {
        $('#person_A_details').validate({ 
            rules: {
                CONTACTS_EMAIL: {
                    required: true,
                    email: true
                },
                CONTACTS_LNAME: "required",
                CONTACTS_FNAME: "required",
                CONTACTS_GENDER: "required",
                CONTACTS_PHONE: "required",
                CONTACTS_LANGUAGE: "required",
                CONTACTS_FIXEDPARTNER: "required",
                PRODUCT_SELECT: "required",
            },
            messages: {
                CONTACTS_FNAME: "<?php echo $FRM_ERRMSG_CONTACTS_FNAME;?>",
                CONTACTS_LNAME: "<?php echo $FRM_ERRMSG_CONTACTS_LNAME;?>",
                CONTACTS_GENDER: "<?php echo $FRM_ERRMSG_CONTACTS_GENDER;?>",
                CONTACTS_PHONE: "<?php echo $FRM_ERRMSG_CONTACTS_PHONE;?>",
                CONTACTS_LANGUAGE: "<?php echo $FRM_ERRMSG_CONTACTS_LANGUAGE;?>",
                CONTACTS_FIXEDPARTNER: "<?php echo $FRM_ERRMSG_CONTACTS_FIXEDPARTNER;?>",
                PRODUCT_SELECT: "<?php echo $FRM_ERRMSG_PRODUCT_SELECT;?>",
                CONTACTS_EMAIL: {
                  required: "<?php echo $FRM_ERRMSG_CONTACTS_EMAIL;?>",
                  email: "<?php echo $FRM_ERRMSG_CONTACTS_EMAIL_FORMAT;?>"
                }
              },
            submitHandler: function (form) { 
                $("#FIRST_PAGE_submitbtn").attr("disabled", "disabled");
                //$( "#FIRST_PAGE_submitbtn" ).prop( "disabled", true ); -> I also trief the prop but this does not work either in safari
                 form.submit();
            }
        });
            $('#PARTNER_DETAILS').validate({ 
                rules: {
                    PARTNER_CONTACTS_EMAIL: {
                        required: true,
                        email: true
                    },
                    PARTNER_CONTACTS_FNAME: "required",
                    PARTNER_CONTACTS_LNAME: "required",
                    PARTNER_CONTACTS_GENDER: "required",
                    CONTACTS_PRIVACY_POLICY_AGREE: "required",
                },
                messages: {
                    PARTNER_CONTACTS_FNAME: "<?php echo $FRM_ERRMSG_PARTNER_CONTACTS_FNAME;?>",
                    PARTNER_CONTACTS_LNAME: "<?php echo $FRM_ERRMSG_PARTNER_CONTACTS_LNAME;?>",
                    PARTNER_CONTACTS_GENDER: "<?php echo $FRM_ERRMSG_PARTNER_CONTACTS_GENDER;?>",
                    CONTACTS_PRIVACY_POLICY_AGREE: "<?php echo $FRM_ERRMSG_CONTACTS_PRIVACY_POLICY_AGREE;?>",
                    PARTNER_CONTACTS_EMAIL: {
                      required: "<?php echo $FRM_ERRMSG_PARTNER_CONTACTS_EMAIL;?>",
                      email: "<?php echo $FRM_ERRMSG_PARTNER_CONTACTS_EMAIL_FORMAT;?>"
                    }
                  },
                submitHandler: function (form) { 
                    $("#PARTNER_DETAILS_submitbtn").attr("disabled", "disabled");
                     form.submit();
                }
            });
            $('#NO_PARTNER').validate({ 
                rules: {
                    CONTACTS_AGE: "required",
                    CONTACTS_HEIGHT: "required",
                    CONTACTS_PRIVACY_POLICY_AGREE: "required",
                },
                messages: {
                    CONTACTS_AGE: "<?php echo $FRM_ERRMSG_CONTACTS_AGE;?>",
                    CONTACTS_HEIGHT: "<?php echo $FRM_ERRMSG_CONTACTS_HEIGHT;?>",
                    CONTACTS_PRIVACY_POLICY_AGREE: "<?php echo $FRM_ERRMSG_CONTACTS_PRIVACY_POLICY_AGREE;?>",
                  },
                submitHandler: function (form) { 
                    $("#NO_PARTNER_submitbtn").attr("disabled", "disabled");
                     form.submit();
                }
            });

        });

这是我的生成HTML的php代码

<body>
<?php
if(!isset($_POST['person_A_details'])) {
    echo "<!--<h1><b>".$P1_TITLE."</b></h1>-->
    <form name='person_A_details' id='person_A_details' method='post' action='' >
    ".$PRODUCT_SELECT_TXT.$REQ_AST."<label for='PRODUCT_SELECT' class='error' style='display:none;'></label><br>";

    $sql= "SELECT CRM_PRODUCTS.ID, CRM_PRODUCTS.PRODUCTS_NAME, CRM_PRODUCTS.PRODUCTS_WEBNAME_EN, CRM_PRODUCTS.PRODUCTS_WEBNAME_FR,CRM_PRODUCTS.PRODUCTS_WEBNAME_NL,CRM_PRODUCTS.PRODUCTS_TIMING,CRM_PRODUCTS.PRODUCTS_DATES, CRM_LOCATIONS.LOCATIONS_CITY,CRM_LOCATIONS.LOCATIONS_CITY_FR, CRM_LOCATIONS.LOCATIONS_CITY_NL FROM CRM_PRODUCTS JOIN CRM_LOCATIONS ON CRM_PRODUCTS.LOCATIONS_ID=CRM_LOCATIONS.LOCATIONS_ID WHERE CRM_PRODUCTS.PRODUCTS_PUBLISHONWEBSITE=1 AND CRM_PRODUCTS.PRODUCTS_TYPE='Weekly_class' order by CRM_PRODUCTS.PRODUCTS_CREATEDATE";
    $result = mysqli_query($coni,$sql);

    while ($row = mysqli_fetch_array($result)){
        if ($language=="EN") echo "<input type='radio' name='PRODUCT_SELECT' value=".$row['ID'].">".$row['PRODUCTS_WEBNAME_EN']."<br>";
        if ($language=="FR") echo "<input type='radio' name='PRODUCT_SELECT' value=".$row['ID'].">".$row['PRODUCTS_WEBNAME_FR']."<br>";
        if ($language=="NL") echo "<input type='radio' name='PRODUCT_SELECT' value=".$row['ID'].">".$row['PRODUCTS_WEBNAME_NL']."<br>";
    }
    echo $FNAME.$REQ_AST."<label for='CONTACTS_FNAME' class='error' style='display:none;'></label><input type='text' name='CONTACTS_FNAME'><br>
    ".$LNAME.$REQ_AST."<label for='CONTACTS_LNAME' class='error' style='display:none;'></label><input type='text' name='CONTACTS_LNAME'><br>
    ".$GENDER.$REQ_AST."<label for='CONTACTS_GENDER' class='error' style='display:none;'></label><br>
    <input type='radio' name='CONTACTS_GENDER' value='M'> ".$GENDER_M."
    <input type='radio' name='CONTACTS_GENDER' value='F'> ".$GENDER_F."<br>
    <br>
    ".$EMAIL.$REQ_AST."<label for='CONTACTS_EMAIL' class='error' style='display:none;'></label><input type='text' name='CONTACTS_EMAIL'><br>
    ".$P1_PHONE.$REQ_AST."<label for='CONTACTS_PHONE' class='error' style='display:none;'></label><input type='text' name='CONTACTS_PHONE'><br>
    ".$P1_POSTALCODE."<input type='text' name='CONTACTS_POSTALCODE'><br>
    ".$P1_PREF_LANG.$REQ_AST."<label for='CONTACTS_LANGUAGE' class='error' style='display:none;'></label> <select name='CONTACTS_LANGUAGE'>
    <option value=''></option>
    <option value='EN'>English</option>
    <option value='FR'>Français</option>
    <option value='NL'>Nederlands</option>
    </select><br>
    ".$P1_DANCEPARTNER_SELECT.$REQ_AST." <label for='CONTACTS_FIXEDPARTNER' class='error' style='display:none;'></label><select name='CONTACTS_FIXEDPARTNER'>
    <option value=''></option>
    <option value='yes'>".$PARTNER_YES."</option>
    <option value='no'>".$PARTNER_NO."</option>
    </select><br>
    ".$P1_REMARKS."<textarea rows = '3' name='PRODUCTS_PURCHASE_REMARKS'></textarea><br>
    <br><br>
    <input type='submit' name='person_A_details' value='".$P_SUBMIT."' id='FIRST_PAGE_submitbtn'>
    </form>";
}

if(isset($_POST['person_A_details']) && $_POST['CONTACTS_FIXEDPARTNER']=='yes') {

    //log progress of form in post.log
    $log_date = date("d/m/y : H:i :");
    $log_content =  $log_date. " ".
                    $_POST['PRODUCT_SELECT']." ".
                    $_POST['CONTACTS_FNAME']." ".
                    $_POST['CONTACTS_LNAME']." ".
                    $_POST['CONTACTS_GENDER']." ".
                    $_POST['CONTACTS_EMAIL']." ".
                    $_POST['CONTACTS_PHONE']." ".
                    $_POST['CONTACTS_POSTALCODE']." ".
                    $_POST['CONTACTS_LANGUAGE']." ".
                    $_POST['CONTACTS_FIXEDPARTNER']." ".
                    $_POST['PRODUCTS_PURCHASE_REMARKS']." ";

    file_put_contents("post_paid_class.log",$log_content, FILE_APPEND);
    //end log

    echo "
    <form name='PARTNER_DETAILS' id='PARTNER_DETAILS' method='post' action='register_class_submit.php'>
    <h2>".$P_DP_TITLE."</h2>
    ".$FNAME.$REQ_AST."<label for='PARTNER_CONTACTS_FNAME' class='error' style='display:none;'></label><input type='text' name='PARTNER_CONTACTS_FNAME'><br>
    ".$LNAME.$REQ_AST."<label for='PARTNER_CONTACTS_LNAME' class='error' style='display:none;'></label><input type='text' name='PARTNER_CONTACTS_LNAME'><br>
    ".$EMAIL.$REQ_AST."<label for='PARTNER_CONTACTS_EMAIL' class='error' style='display:none;'></label><input type='text' name='PARTNER_CONTACTS_EMAIL'><br>
    ".$GENDER.$REQ_AST."<label for='PARTNER_CONTACTS_GENDER' class='error' style='display:none;'></label><br>
    <input type='radio' name='PARTNER_CONTACTS_GENDER' value='M'> ".$GENDER_M."
    <input type='radio' name='PARTNER_CONTACTS_GENDER' value='F'> ".$GENDER_F."<br><br>
    <input type='checkbox' name='CONTACTS_PRIVACY_POLICY_AGREE'>".$PRIVACY_POLICY.$REQ_AST." <label for='CONTACTS_PRIVACY_POLICY_AGREE' class='error' style='display:none;'></label>
    <br><br>
    <input type='hidden' name='PRODUCT_SELECT' value='".$_POST['PRODUCT_SELECT']."'>
    <input type='hidden' name='CONTACTS_FNAME' value='".$_POST['CONTACTS_FNAME']."'>
    <input type='hidden' name='CONTACTS_LNAME' value='".$_POST['CONTACTS_LNAME']."'>
    <input type='hidden' name='CONTACTS_GENDER' value='".$_POST['CONTACTS_GENDER']."'>
    <input type='hidden' name='CONTACTS_EMAIL' value='".$_POST['CONTACTS_EMAIL']."'>
    <input type='hidden' name='CONTACTS_PHONE' value='".$_POST['CONTACTS_PHONE']."'>
    <input type='hidden' name='CONTACTS_POSTALCODE' value='".$_POST['CONTACTS_POSTALCODE']."'>
    <input type='hidden' name='CONTACTS_LANGUAGE' value='".$_POST['CONTACTS_LANGUAGE']."'>
    <input type='hidden' name='CONTACTS_FIXEDPARTNER' value='".$_POST['CONTACTS_FIXEDPARTNER']."'>
    <input type='hidden' name='PRODUCTS_PURCHASE_REMARKS' value='".$_POST['PRODUCTS_PURCHASE_REMARKS']."'>
    <input type='submit' name='PARTNER_DETAILS' value='".$P_SUBMIT."' id='PARTNER_DETAILS_submitbtn'>
    </form>";
    echo $CLICK_ONCE;
}

if(isset($_POST['person_A_details']) && $_POST['CONTACTS_FIXEDPARTNER']=='no') {
    //log progress of form in post.log
    $log_date = date("d/m/yyyy : H:i :");
    $log_content =  $log_date. " ".
                    $_POST['PRODUCT_SELECT']." ".
                    $_POST['CONTACTS_FNAME']." ".
                    $_POST['CONTACTS_LNAME']." ".
                    $_POST['CONTACTS_GENDER']." ".
                    $_POST['CONTACTS_EMAIL']." ".
                    $_POST['CONTACTS_PHONE']." ".
                    $_POST['CONTACTS_POSTALCODE']." ".
                    $_POST['CONTACTS_LANGUAGE']." ".
                    $_POST['CONTACTS_FIXEDPARTNER']." ".
                    $_POST['PRODUCTS_PURCHASE_REMARKS']." ";

    file_put_contents("post_paid_class.log",$log_content, FILE_APPEND);
    //end log

    echo "
    <form name='NO_PARTNER' id='NO_PARTNER' method='post' action='register_class_submit.php'>
    <h2>".$P_NP_TITLE."</h2>
    ".$P_NP_DESC."<br><br>
    ".$P_NP_AGE.$REQ_AST."<label for='CONTACTS_AGE' class='error' style='display:none;'></label> <input type='text' name='CONTACTS_AGE'><br>
    ".$P_NP_HEIGHT.$REQ_AST."<label for='CONTACTS_HEIGHT' class='error' style='display:none;'></label> <input type='text' name='CONTACTS_HEIGHT'><br>
    ".$P_NP_OTHLANG." <br>
    <input type='checkbox' name='CONTACTS_OTHER_LANGUAGES[]' value='EN'> English<br>
    <input type='checkbox' name='CONTACTS_OTHER_LANGUAGES[]' value='FR'> Français<br>
    <input type='checkbox' name='CONTACTS_OTHER_LANGUAGES[]' value='NL'> Nederlands<br>
    <input type='checkbox' name='CONTACTS_OTHER_LANGUAGES[]' value='DE'> German<br>
    <input type='checkbox' name='CONTACTS_OTHER_LANGUAGES[]' value='ES'> Spanish<br>
    <input type='checkbox' name='CONTACTS_OTHER_LANGUAGES[]' value='IT'> Italian<br>
    ".$P_NP_OTH." <input type='text' name='CONTACTS_OTHER_LANGUAGES[]'><br><br>
    <input type='checkbox' name='CONTACTS_PRIVACY_POLICY_AGREE'>".$PRIVACY_POLICY.$REQ_AST." <label for='CONTACTS_PRIVACY_POLICY_AGREE' class='error' style='display:none;'></label>
    <br><br>
    <input type='hidden' name='PRODUCT_SELECT' value='".$_POST['PRODUCT_SELECT']."'>
    <input type='hidden' name='CONTACTS_FNAME' value='".$_POST['CONTACTS_FNAME']."'>
    <input type='hidden' name='CONTACTS_LNAME' value='".$_POST['CONTACTS_LNAME']."'>
    <input type='hidden' name='CONTACTS_GENDER' value='".$_POST['CONTACTS_GENDER']."'>
    <input type='hidden' name='CONTACTS_EMAIL' value='".$_POST['CONTACTS_EMAIL']."'>
    <input type='hidden' name='CONTACTS_PHONE' value='".$_POST['CONTACTS_PHONE']."'>
    <input type='hidden' name='CONTACTS_POSTALCODE' value='".$_POST['CONTACTS_POSTALCODE']."'>
    <input type='hidden' name='CONTACTS_LANGUAGE' value='".$_POST['CONTACTS_LANGUAGE']."'>
    <input type='hidden' name='CONTACTS_FIXEDPARTNER' value='".$_POST['CONTACTS_FIXEDPARTNER']."'>
    <input type='hidden' name='PRODUCTS_PURCHASE_REMARKS' value='".$_POST['PRODUCTS_PURCHASE_REMARKS']."'>  
    <input type='submit' name='NO_PARTNER' value='".$P_SUBMIT."' id='NO_PARTNER_submitbtn'>
    </form>";
    echo $CLICK_ONCE;
}
}

mysqli_close($coni);

?>

0 个答案:

没有答案