title: How can I setup custom error messages for each form field in Codeigniter?
body: <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>