• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validation of a checkbox using the "required" rule

#1
[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.

#2
[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

#3
[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.

#4
[eluser]Pascal Kriete[/eluser]
Checkboxes use the 'isset' text, not the 'required' text.
This really should be documented.

#5
[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';

#6
[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!

#7
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.