Welcome Guest, Not a member yet? Register   Sign In
form validation - default msg showing instead of my own
#1

[eluser]stef25[/eluser]
i have a checkbox that needs be checked to "agree with terms and conditions" that im trying to validate. i set my rule:
Code:
$rules['chk_approval'] = "required";

then i have a message:
Code:
$this->validation->set_message('required', 'This field is required: ');

on blank text fields i get 'this field is required' showing up, but on the checkbox i get ' The Agree to terms and conditions field must have a value. ' I guess this is some kind of default message that shows, but why do i not get the message I configged? 'must have a value' isnt really proper feedback in this case.

do i have an error in my code somewhere or is this standard for validation of a checkbox? its NOT taking the error message I set at all. Anyone know why?
#2

[eluser]stef25[/eluser]
I decided to write my own validation function, but neither of these echo messages seem to come out. the checkbox markup:

Code:
<input type="checkbox" class="checkbox" id="chk_approval" value="accept" name="chk_approval"/>

Then my validation function:
Code:
$rules['chk_approval'] = "callback_checkbox_check";
                
                //custom validation function for the checkbox
                function checkbox_check() {
                    $value = "accept";
                    if($this->post->chk_approval == $value) {
                        echo "OK!";
                    }                        
                    else {
                        echo "not OK!";
                    }

Is this code wrong?
#3

[eluser]Unknown[/eluser]
change this
Code:
$this->validation->set_message('required', 'This field is required: ');
to this
Code:
$this->validation->set_message('isset', 'This field is required: ');
i hope it works.




Theme © iAndrew 2016 - Forum software by © MyBB