Grigor
Grigor

Reputation: 4049

CodeIgniter set error message with value in message

So I read the user guide for form validation and there it shows how to set custom message. For example, if I put this in my code

$this->form_validation->set_message('is_unique', '%s address already registered.');

it will output E-mail address already registered. (If it is validation for email field)

What I want to do is have a message that will say E-mail address [email protected] already registered. Is there a code to put to show the value of the field that is being passed? (like %s, that shows the field name)

Upvotes: 1

Views: 1491

Answers (1)

SeanCannon
SeanCannon

Reputation: 77956

$this->form_validation->set_message('is_unique', '%s address ' . $this->input->post('email', true) . ' already registered.');

Out of the box, it only translates the field name with sprintf, not the field value:

$message = sprintf($line, $this->_translate_fieldname($row['label']), $param);

Simply extend CI_Form_validation with MY_Form_validation and parse the string to fit your needs.

Upvotes: 1

Related Questions