title: Validating Forms
body: <p>I have a form that I submit with jQuery ajax and have it being sent to a controller function called submit to validate and do any other tasks I need to with the form data. I'm trying to find out why my form validation library isn't showing an error when the username doesn't contain only lowercase letters and numbers.</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|xss_clean|strtolower');
  </code></pre>
  
  <p>POST Value after form submission:</p>
  
  <pre><code>username    TestingUSER
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>As far as I know it gets to the php server side properly.</p>
  
  <p>PHP:</p>
  
  <pre><code>public function submit()
  {
      $output_status = 'Notice';
      $output_title = 'Not Processed';
      $output_message = 'The request was unprocessed!';
  
      $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|xss_clean|strtolower');
      $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|xss_clean');
      $this-&gt;form_validation-&gt;set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');
  
      if ($this-&gt;form_validation-&gt;run() == TRUE)
      {
  
      }
      else
      {
          $output_status = 'Error';
          $output_title = 'Form Not Validated';
          $output_message = validation_errors();
      }
  
      echo json_encode(array('output_status' =&gt; $output_status, 'output_title' =&gt; $output_title, 'output_message' =&gt; $output_message));
  }
  </code></pre>
  
  <p>EDIT 2: </p>
  
  <p>Based off of Sheikh answer. I am getting a response back that says "Unable to access an error message corresponding to your field name." It does say Form Not Validated for the title so the message isn't working.</p>
  
  <pre><code>public function check_username($str)
  {
      if (preg_match('#[0-9]#', $str) &amp;&amp; preg_match('#[a-z]#', $str)) 
      {
          return TRUE;
      }
      $this-&gt;form_validation-&gt;set_message('username', 'This is not have an accepted value!');
      return FALSE;
  }
  </code></pre>
  
  <p>EDIT 3: </p>
  
  <p>What I'm wanting to do is have it report back that there there are validation errors but not the specific errors in the pnotify response. However I do want it to display the specific errors under the form elements.</p>
  
  <p>jQuery Code: </p>
  
  <p><a href="http://pastebin.com/1KehMJkh" rel="nofollow">http://pastebin.com/1KehMJkh</a></p>
  
  <p>Login Form:</p>
  
  <p><a href="http://pastebin.com/EfpBfbfN" rel="nofollow">http://pastebin.com/EfpBfbfN</a></p>