Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I setup custom error messages for each form field in Codeigniter?
    primarykey
    data
    text
    <p>i'm trying to setup a codeigniter form with different error messages.</p> <p>set_message(rule, msg) is setting up a message for the whole form.</p> <p>I need:</p> <pre><code>$this-&gt;form_validation-&gt;set_rules('name', 'First Name', 'required'); $this-&gt;form_validation-&gt;set_message('name', 'required', 'Enter your Name'); $this-&gt;form_validation-&gt;set_rules('second', 'Variables', 'required'); $this-&gt;form_validation-&gt;set_message('second', 'required', 'The Variables are required'); </code></pre> <p>Adding the %s into the message string is no help in this case, since the messages have to be completely different.</p> <p>Possibly I could do something like:</p> <h2>controller</h2> <pre><code>$this-&gt;form_validation-&gt;set_rules('name', 'Name', 'required|min_length[6]|max_length[12]'); $this-&gt;form_validation-&gt;set_rules('second', 'Variables', 'required|min_length[3]|max_length[5]'); $this-&gt;form_validation-&gt;set_message('required', 'required'); $this-&gt;form_validation-&gt;set_message('min_length', 'short'); $this-&gt;form_validation-&gt;set_message('max_length', 'long'); </code></pre> <h2>view</h2> <pre><code>switch(form_error('name')) { case '&lt;p&gt;required&lt;/p&gt;': echo 'Enter your Name'; break; case '&lt;p&gt;short&lt;/p&gt;': echo 'min length 6'; break; case '&lt;p&gt;long&lt;/p&gt;': echo 'min length 12'; break; } switch(form_error('second')) { case '&lt;p&gt;required&lt;/p&gt;': echo 'The Variables are required'; break; case '&lt;p&gt;short&lt;/p&gt;': echo 'min length 3'; break; case '&lt;p&gt;long&lt;/p&gt;': echo 'min length 5'; break; } </code></pre> <p>But isn't there a smarter way to do it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload