【发布时间】:2012-03-19 05:50:41
【问题描述】:
所以我有一个需要验证的表单。表单验证的其余部分有效,但是当我使用 php 属性 [] 添加复选框组以将复选框形成数组时。复选框不再适用于我的验证脚本。
$("form[name='violationsForm']").validate({
ignore: ":hidden,[name='']", // do not validate form fields in invisible sections
errorPlacement: function(error, element) {
$(element).attr("class","error");
error.insertAfter(element);
},
rules: {
owner_address: { required: true, minlength: 5 }
,owner_county: { required: true, minlength: 1 }
,date1: { required: true, minlength: 2 }
,time1: { required: true, minlength: 2 }
,timeframe1: { required: true, minlength: 2 }
,violation[]: { required: true}
}
});
添加 ,violation[]: { required: true} 会破坏整个验证脚本。 以下是我的参考表单输入。
<li>
<label><strong>Type of Violation (required):</strong></label><br />
<label>type 1 <input type="checkbox" id="violation" name="violation[]" value="1"
title="Please choose at least ONE violation."/></label><br />
<label>type 2 <input type="checkbox" id="violation" name="violation[]" value="2" />
</label><br />
<label>type 3 <input type="checkbox" id="violation" name="violation[]" value="3" />
</label><br />
<label>type 4 <input type="checkbox" id="violation" name="violation[]" value="4" />
</label><br />
<label>type 5 <input type="checkbox" id="violation" name="violation[]" value="5" />
</label><br />
<label>Other <input type="checkbox" id="violation_0" name="violation[]" value="other" />
</label><br />
</li>
由于我使用的是 php,因此我更愿意将 [] 附加到我的输入“名称”值。有什么想法吗?
谢谢!
【问题讨论】:
标签: php jquery forms jquery-validate