callum.bennett
callum.bennett

Reputation: 686

codeigniter custom form validation error messages

$this->form_validation->set_message('is_date', 'You must enter a valid date.');
$this->form_validation->set_rules('loadingdate', 'Loading Date', 'required|is_date|xss_clean');
$this->form_validation->set_rules('departuredate', 'Departure Date', 'required|is_date|xss_clean');
$this->form_validation->set_rules('arrivaldate', 'Arrival Date', 'required|is_date|xss_clean');
$this->form_validation->set_rules('cutoffdate', 'Cut Off Date', 'required|is_date|xss_clean');
$this->form_validation->set_rules('loadingdate', 'Loading Date', 'required|is_date|xss_clean');

I have created a custom form validation function called 'is_date' , which i have set a custom error message for.

'You must enter a valid date.'

How can I customise the error message so that it displays the field name, since I have multiple fields which will use this validation? eg.

'Loading Date must be a valid date.' 'Cut Off Date must be a valid date.'

Upvotes: 1

Views: 2174

Answers (1)

cwallenpoole
cwallenpoole

Reputation: 81998

Add %s into the string where you want the field name to be:

"The %s field must contain a valid URL."

(I assume you are defining the message in form_validation_lang.php)

Upvotes: 2

Related Questions