开发者

How to show an validation error if there is no checkbox selected in the form on my CakePHP?

开发者 https://www.devze.com 2023-01-08 05:37 出处:网络
I have a simple for开发者_高级运维m with multiple checkboxes and i want to know how i can show an error if there\'s no checkboxes selected?Just check the values returned to the action that are stored

I have a simple for开发者_高级运维m with multiple checkboxes and i want to know how i can show an error if there's no checkboxes selected?


Just check the values returned to the action that are stored in the array $this->array .. and don't call the save() function until you validate it manually.


You probably want to check before the form is submitted. This you will need to do with javascript and to save effort, I suggest you use the jQuery validation plugin:

http://docs.jquery.com/Plugins/Validation

It's extremely easy to use and jQuery offers a lot for developers.


Could always create a custom rule in you model for this behaviour. Or bind together a bunch of 'NOT_EMPTY' rules, then check the $this->Model->validationErrors array for errors.

Although I do think that creating a custom validation function in your model, then calling that using the regular Cake validation would be best. Be sure that all your checkboxes share a common name, as then they'll group together and make your life easier.

0

精彩评论

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

关注公众号