So I have a form which needs to be validated. The rest of the form validation works but when i add the checkbox group using the php attribute [] to form the check box into an array. The checkboxes no longer work with my validation script.
$("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}
}
});
adding ,violation[]: { required: true} Breaks the entire validation script.
Below is my form input for ref.
<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>
Since I am using php I’d prefer to keep [] attached to my input “name” value. Any thoughts?
Thanks!
Surround it in quotes: