Home > Software design >  Codeigniter Form Validation custom message
Codeigniter Form Validation custom message

Time:05-27

I am trying to set custom messages in CI3 for the form validation rules i have set. For this, i am using a config file:

$config = array(
        'register' => array(
                array(
                        'field' => 'username',
                        'label' => 'Username',
                        'rules' => 'trim|required|min_length[5]',
                        'errors'=> array(
                            'required'      => 'Trebuie introdus',
                            'min_length[5]' => 'Minim 5 caractere'
                        )
                ),
rest of arrays

The 'required' rule displays the message i have set.

The 'min_length[5]' displays the standard message. I can't figure out what i am missing :D I have also tried to pass the parameters and still the same.

'min_length[5]' => 'Minim %s caractere'

I don't want to override the global file.

CodePudding user response:

You need to leave off the [5] behind min_length in the errors array to display the custom message:

$config = array(
        'register' => array(
                array(
                        'field' => 'username',
                        'label' => 'Username',
                        'rules' => 'trim|required|min_length[5]',
                        'errors'=> array(
                            'required'      => 'Trebuie introdus',
                            'min_length' => 'Minim 5 caractere'
                        )
                ),
rest of arrays
  • Related