How to customize form validation errors in codeIgniter

前端 未结 8 2298
刺人心
刺人心 2021-01-05 07:18

Is there a file in codeIgniter in which I could just edit so that I can customize the form validation messages?

<script

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 07:36

    3 Ways to format/ customize error display

    1. Changing delimiters Globally: To globally change the error delimiters, in your controller method, just after loading the Form Validation class. Load after the form_validation library load. you can load in the constructor as well.

    $this->form_validation->set_error_delimiters('
    ', '
    ');

    2.Changing delimiters Individually: Each of the two error generating functions shown in this tutorial can be supplied their own delimiters as follows

    ', '
    '); ?> OR ', '
'); ?>

3. Set delimiters in a config file: You can add your error delimiters in application/config/form_validation.php as follow. Set this 2 config variable in the file. $config['error_prefix'] ='

'; and $config['error_suffix'] = '
';

Ref Link: https://www.codeigniter.com/userguide3/libraries/form_validation.html#changing-the-error-delimiters

提交回复
热议问题