Welcome Guest, Not a member yet? Register   Sign In
validation of a checkbox using the "required" rule

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.

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:
$this->validation->set_message('required', 'Your custom message here');

Replace ="required" with code above

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.

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..?

$_POST['checkbox'] == 'checked_value';

I made another post with a similar problem and that post may answer this post for you:


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.

Theme © iAndrew 2016 - Forum software by © MyBB