![]() |
%s values in custom error messages - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: %s values in custom error messages (/showthread.php?tid=12717) |
%s values in custom error messages - El Forum - 10-29-2008 [eluser]wdm*[/eluser] I'm displaying the form validation errors individually inline with the form with Code: <?= form_error('my_field') ?> So the field name is not needed in the error message, it should rather just read e.g. Quote:must be at least %s characters in length The problem I have is that the %s gets replaced with the field name, not the number. Looking at the original string in language/english/form_validation_lang.php it looks like the first %s is always the name, the second %s always the number Is there any way to change this? %s values in custom error messages - El Forum - 10-29-2008 [eluser]xwero[/eluser] Short answer no. The only way i can think of to do this with the least amount of code is Code: $at_least = 3; Code: $this->validation_form->set_message('at_least',sprintf(lang('at_least'),$at_least)); %s values in custom error messages - El Forum - 10-29-2008 [eluser]wr5aw[/eluser] You could override [your system folder]/language/english/form_validation_lang.php by copying it to [your application folder]/language/english/form_validation_lang.php. Then just make the change in the copy. From the user guide (v1.7): Quote:Language files are typically stored in your system/language directory. Alternately you can create a folder called language inside your application folder and store them there. CodeIgniter will look first in your system/application/language directory. If the directory does not exist or the specified language is not located there CI will instead look in your global system/language folder. %s values in custom error messages - El Forum - 10-29-2008 [eluser]xwero[/eluser] wr5aw how will that solve his problem wanting the param to be the first/only thing that needs to be replaced in the error message? %s values in custom error messages - El Forum - 10-29-2008 [eluser]wr5aw[/eluser] [quote author="xwero" date="1225304002"]wr5aw how will that solve his problem wanting the param to be the first/only thing that needs to be replaced in the error message?[/quote] You're right. I should know better than to post off the top of my head before morning coffee. :gulp: %s values in custom error messages - El Forum - 10-29-2008 [eluser]drewbee[/eluser] Can this not simply be taken care of by identifying the current %s in the message? CI usess sprint_f to do this, so it is a breeze... %1$s = accesses first passed variable %2$s = accesses second passed variable So the error message should be... "must be at least %2$s characters in length" I also display my error messages in-line and this worked like a breeze. %s values in custom error messages - El Forum - 10-29-2008 [eluser]xwero[/eluser] nice solution drewbee! |