Welcome Guest, Not a member yet? Register   Sign In
Custom error message
#1

[eluser]jakeone[/eluser]
Hi

I'm validating my form using an array as shown in the user guide, i.e.

Code:
$config = array(
               array(
                     'field'   => 'username',
                     'label'   => 'Username',
                     'rules'   => 'required'
                  ),
               array(
                     'field'   => 'password',
                     'label'   => 'Password',
                     'rules'   => 'required'
                  ),
               array(
                     'field'   => 'passconf',
                     'label'   => 'Password Confirmation',
                     'rules'   => 'required'
                  ),  
               array(
                     'field'   => 'email',
                     'label'   => 'Email',
                     'rules'   => 'required'
                  )
            );

$this->form_validation->set_rules($config);

Can someone tell me the correct syntax to create a custom an error message for each rule? Yes, I know I can use
Code:
$this->form_validation->set_message('rule', 'Error Message');
but I want to do it from within the array.

Thanks
#2

[eluser]codeshadow[/eluser]
Hi,

Do you mean to say that just like the $config array you wish to have one more array that would hold your custom error messages? Well if it is so, then try this:

Code:
$mess = array('required' => 'You gotto add something to this dude',
                .....
              );

And then pass it to set_message() just like the way you pass an array to set_rules:

Code:
$this->form_validation->set_rules($mess);

There you go, all your custom messages in one array :coolsmile:
#3

[eluser]jakeone[/eluser]
It's not quite what I meant - sorry I should have been clearer. What I mean was, is there an array key I could set to hold a custom error message when using an array to process the validation, e.g.

Code:
$config = array(
               array(
            'field'   => 'username',
            'label'   => 'Username',
            'rules'   => 'required',
            'custom_error_msg' => 'custom error message 1'

                  ),
               array(
            'field'   => 'password',
            'label'   => 'Password',
            'rules'   => 'required'
            'custom_error_msg' => 'custom error message 2'
                  ),
            );

$this->form_validation->set_rules($config);

Not sure if this is possible.

Thanks

Jake




Theme © iAndrew 2016 - Forum software by © MyBB