0
我正在使用Jquery驗證插件來驗證動態窗體。我得到的錯誤消息是想要的,但主要問題是所需的字段是空或不管條件提交按鈕仍然工作。如果必填字段爲空,我無法停止提交。這是我的代碼的一小部分。Jquery驗證插件(.validate)不工作在動態表單(循環窗體)
HTML:
<form class="pa-form" action="confirmed" method="post" id="my-form">
<fieldset>
<?php for($i=1;$i<=3;$i++){ ?>
<div class="flabel-control">
<input data-toggle="floatLabel" data-value="" name="myForm[first_name][]" class="firstname form-control" type="text" id="first-name<?=$i?>" required placeholder="First name" spellcheck="false">
</div>
<div class="flabel-control">
<input data-toggle="floatLabel" data-value="" name="myForm[last_name][]" class="firstname form-control" type="text" id="last-name<?=$i?>" required placeholder="Last name" spellcheck="false">
</div>
<br>
<?php };?>
<div class="btn-holder">
<input type="submit" id="submitBtn" class="btn btn-default text-uppercase" value="Confirm">
</div>
</fieldset>
</form>
JS:
$("#my-form").validate({
validClass: "valid",
errorClass: "error",
rules: {
'myForm[first_name][]': "required",
'myForm[last_name][]': "required",
},
messages: {
'myForm[first_name][]': "First name is required",
'myForm[last_name][]': "Last name is required",
}
}
});
http://stackoverflow.com/questions/24670447/how-to-validate-array-of-inputs-using-validate-plugin-jquery」 – coolguy
解決方案他們只能用於單個數組。我無法找到多維數組的解決方案 – Kais