Welcome Guest, Not a member yet? Register   Sign In
Still can't get form validation to work
#1

I am getting

Unable to access an error message corresponding to your field name First name.(name_check)

This is my code




Code:
public function name_check($str)
        { 

if (Is_a_Letter_or_Space_etc($value)) {
return TRUE;
}
else {
$this->CI->form_validation->set_message('name_check', "The %s may only contain Alpha Numeric Characters and Spaces , /\ . & - ' ");
return FALSE;
}
    }

function Is_a_Letter_or_Space_etc($inputbox) { 

$teststring = Trim($inputbox);
if ($teststring == "") {
return False;

}

$i = 0;
while ($i <= strlen($teststring) - 1) {
$c = strtolower(substr($teststring,$i,1));

if ($c <> "a" & $c <> "b" & $c <> "c" & $c <> "d" & $c <> "e" & $c <> "f" & $c <> "g" & $c <> "h" & $c <> "i" & $c <> "j" & $c <> "k" & $c <> "l" & $c <> "m" & $c <> "n" & $c <> "o" & $c <> "p" & $c <> "q" & $c <> "r" & $c <> "s" & $c <> "t" & $c <> "u" & $c <> "v" & $c <> "w" & $c <> "x" & $c <> "y" & $c <> "z" & $c <> " " & $c <> "/" & $c <> "," & $c <> "&" & $c <> "." & $c <> "-" & $c <> "'" & $c <> "\\") {
return False;
}
$i = $i + 1;
}
return True;
}






This is my rules

'order-info-form' => array(
                                    array(
                                            'field' => 'order_first_name',
                                            'label' => 'First name',
                                            'rules' => 'trim|required|name_check'
                                        ),
                                    array(
                                            'field' => 'order_last_name',
                                            'label' => 'Last name',
                                            'rules' => 'trim|required|name_check'
                                        ),



I have tried callback_  as well but it doesn't make any difference. I am also getting that when the input is valid


Thanks
Unable to access an error message corresponding to your field name First name.(name_check)
Unable to access an error message corresponding to your field name First name.(name_check)
Reply
#2

As I sadi


'rules' => 'trim|required|callback_name_check'

didn't work either. That was the thing I tried


but I have just spotted that


$this->CI->form_validation->set_message('name_check', "The %s may only contain Alpha Numeric Characters and Spaces , /\ . & - ' ");

should be

$this->form_validation->set_message('name_check', "The %s may only contain Alpha Numeric Characters and Spaces , /\ . & - ' ");


but wether that is the problem I don't know until I try it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB