开发者

Codeigniter validation

Based on the backend data i may have n number of items displayed along with the check box开发者_StackOverflow中文版 and textarea for selecting and give commnet on the page and there is also a option given to the user to remove the items based on the requirements. I need to set a validation like atlease one item is required. Since its number is based on the query dont know how to set the validation.


It's hard to say without a bit more detail, but in general if you have a set of checkboxes and you want to make sure at least one is checked you could do this in your HTML:

<p><input type="checbox" name="my_field_name[]" value="item1" />Item 1</p>
<p><input type="checbox" name="my_field_name[]" value="item2" />Item 2</p>
<p><input type="checbox" name="my_field_name[]" value="item3" />Item 3</p>

and just set a rule that "my_field_name" is a required field. That's assuming it works for you to have the values returned in one array like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜