validation of a checkbox using the "required" rule |
[eluser]CIfan1000[/eluser]
If in my controller I have the following validation of a checkbox: $rules['CheckboxUserAgreement'] = "required"; Then, if the checkbox is not checked, the view containing the checkbox displays: The User agreement checkbox field must have a value. I would like it to say: The User agreement checkbox field is required. Please help.
[eluser]faxtion[/eluser]
Hopefully this makes sense: Quote:Note: You can apply your own custom error messages to any rule, just by setting the message similarly. For example, to change the message for the "required" rule you will do this: Code: $this->validation->set_message('required', 'Your custom message here'); Replace ="required" with code above
[eluser]CIfan1000[/eluser]
Hi, Thanks for your message. I know what you mean but the required rule does say "required" for text fields already. It is just for a check box that it says it needs a value.
[eluser]Pascal Kriete[/eluser]
Checkboxes use the 'isset' text, not the 'required' text. This really should be documented.
[eluser]crumpet[/eluser]
when i use $rules['checkbox'] = "isset" it doesn't seem to work i suspect that the test passes because $_POST['checkbox'] = '' or something. is there a function to check equality to a value..? ie $_POST['checkbox'] == 'checked_value';
[eluser]CIfan1000[/eluser]
I made another post with a similar problem and that post may answer this post for you: http://ellislab.com/forums/viewthread/93667/ It did for me. Thanks to all the helpful people on CI forums!
[eluser]Pascal Kriete[/eluser]
Crumpet, it uses the isset error message (which is why I used 'text' above, but I suppose it wasn't very clear). The rule is still called required. |
Welcome Guest, Not a member yet? Register Sign In |