Welcome Guest, Not a member yet? Register   Sign In
Multiple is_unique and set_message
#1

[eluser]Noobigniter[/eluser]
Hi,

I try for a while, despite the documentation, to define a message for each is_unique, but without success.

Everything works well with one set_message.

If I add one, it overrides the previous one, so I tried this:
Code:
$this->form_validation->set_rules(' ... |is_unique[menu.page]|xss_clean');
$this->form_validation->set_message('is_unique[menu.page]', 'Cette %s est déjà présente.');
but I get the following error:
Code:
Unable to access an error message corresponding to your field name.

How to proceed to have several different messages ?
It is necessary to use personal callback_ ?

In advance, thank you.
#2

[eluser]porquero[/eluser]
I think that you should try set message without table.field:

Code:
$this->form_validation->set_rules(' ... |is_unique[menu.page]|xss_clean');
$this->form_validation->set_message('is_unique', 'Cette %s est déjà présente.');
#3

[eluser]Noobigniter[/eluser]
Yes, for a field it works fine, but I want different message for each, like this example:
Code:
$this->form_validation->set_rules('page', 'Page', '... |is_unique|xss_clean');
$this->form_validation->set_message('is_unique', 'Cette %s est déjà présente, blabla blabla blabla');  

$this->form_validation->set_rules('otherfield', 'Otherfield', ' ... |is_unique|xss_clean');
$this->form_validation->set_message('is_unique', 'Ce %s est déjà présent, huh huuh huh huuh huh');

I thought it was possible to do directly, but if this is not the case, I would call the callback
#4

[eluser]CroNiX[/eluser]
Unfortunately the error message is set by the rule name and not the individual field. I've seen some code in the wiki that let's you set it by the individual field, but haven't tried it.

You can always copy the is_unique() method into a MY_Form_validation extension and rename it to something else and set a new custom error message as a workaround. Not the most efficient and violates DRY principles, but it works.
#5

[eluser]Noobigniter[/eluser]
Ok, thank you for the clarification.
I'll go see it, and at worst I will use the callback.

Wink
#6

[eluser]bretticus[/eluser]
Grrr. Super lame! Means I have to create a callback that calls unique in order to use it multiple times per form submission and have multiple custom error messages.




Theme © iAndrew 2016 - Forum software by © MyBB