问题
i want to set different error message for each field in the form.This is my controller..
$this->form_validation->set_rules('fname', 'First Name','required');
$this->form_validation->set_message('required', 'कृपया प्रथम नाव भरा','fname');
$this->form_validation->set_rules('address', 'Address','required');
$this->form_validation->set_message('required', 'कृपया पत्ता भरा','address');
but problem is that if validation fails it print only error message for last field.
回答1:
I solved it ...first of all autoload form helper and thern in view file
<?php if (form_error('gender'))
{
echo "कृपया लिंग निवडा";
}
;?>
where 'gender' is my field name.And I do it for each field in my form.
回答2:
Hi you have to the following thing if you use
<?php echo validation_errors();?>
this will print all error in one place if you want to print each field with its own error then use this
<? echo form_input('field_name').br().form_error('field_name') ?>
if you are using multi language site then put your all error message in language files
please read form validation doc for complete understanding
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#errordelimiters
来源:https://stackoverflow.com/questions/21509180/how-to-set-error-message-for-each-field-in-codeigniter-php