CodeIgniter Forums
Display min_length - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Display min_length (/thread-16549.html)



Display min_length - El Forum - 03-10-2009

[eluser]ameur[/eluser]
Hello,
Please i want to display the value of min_length in my costum message because i've use it in two times (field username and field password)
this is my code:
Code:
$this->load->library('form_validation');
                
                $this->form_validation->set_rules('username', 'Identifiant', 'trim|required|min_length[3]|alpha_numeric|xss_clean|callback__valid_username');
                $this->form_validation->set_rules('pwd', 'Mot de passe', 'trim|required|min_length[5]|md5');
                $this->form_validation->set_rules('email', 'Email', 'trim|valid_email');
                
                
                $this->form_validation->set_message('required', '» champ obligatoire');
                $this->form_validation->set_message('min_length', '» ce champ doit contenir au moins /*something missing here!!!*/ caracteres');
                $this->form_validation->set_message('_valid_username', '» cet identifiant est déja utilise');
                $this->form_validation->set_message('valid_email', '» email invalide');
                
                $this->form_validation->set_error_delimiters('<span class="single_error">', '</span>');
thank you Smile


Display min_length - El Forum - 03-10-2009

[eluser]xwero[/eluser]
You have to use placeholders to show the parameter, 3. The messages are formatted using sprintf so
Code:
$this->form_validation->set_message('min_length', '&raquo; ce champ doit contenir au moins %2$d caracteres');

A tip if your site is in French work with language files to set your messages instead of adding them to your code. And why not do
Code:
$this->form_validation->set_error_delimiters('<span class="single_error">&raquo; ', '</span>');



Display min_length - El Forum - 03-10-2009

[eluser]ameur[/eluser]
thank you, i try it but it did'nt work :-S


Display min_length - El Forum - 03-10-2009

[eluser]xwero[/eluser]
somehow the percent sign was removed so the place holder is %2$d, or maybe i just forgot to type it Smile


Display min_length - El Forum - 03-10-2009

[eluser]ameur[/eluser]
yes it works :lol:
thank you very well ;-)