title: Codeigniter form validation is not showing errors
body: <p>I'm new to Codegniter so go easy on me.  I'm building a simple login form and I have successfully redirected to a page when the login credentials are correct.  However, if I submit an empty form I get no error messages.  I'm also using <code>set_value</code> in the form field and codeigniter does not refill what the user inputted once the form is submitted.  Somehow that data is being cleared.  Here are a few things i've done for clarity sake.</p>
  <ol>
  <li>Auto-loaded the form_validation library</li>
  <li>Auto-loaded form helper</li>
  <li>Echoed <code>validation_errors</code> above form</li>
  </ol>
  <hr />
  <h1>account.php (controller)</h1>
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
    class Account extends CI_Controller {
  
      public function __construct()
      {
        parent::__construct();
        $this-&gt;load-&gt;model('User_model', 'user');
      }
  
      public function index() {
        $this-&gt;load-&gt;view('home');
      }
  
      public function validate() {
  
        $this-&gt;form_validation-&gt;set_rules('username', 'username', 'xss_clean|required');
        $this-&gt;form_validation-&gt;set_rules('password', 'password', 'xss_clean|required|md5');
  
        $user_data = array(
          'username' =&gt; $this-&gt;input-&gt;post('username'),
          'password' =&gt; MD5($this-&gt;input-&gt;post('password'))
        );
  
        if ($this-&gt;form_validation-&gt;run() == FALSE)
        {
          $data['title'] = &quot;Login Fool&quot;;
          $this-&gt;load-&gt;view('templates/header', $data);
          $data['contents'] = $this-&gt;load-&gt;view('login_view', $data, TRUE);
          $this-&gt;load-&gt;view('page', $data);
          $this-&gt;load-&gt;view('templates/footer');
        }
        else
        {
          $validated = $this-&gt;user-&gt;validate($user_data['username'], $user_data['password']);
          if($validated){
            redirect(base_url() . 'account');
          }
          else{
            $this-&gt;session-&gt;set_flashdata('LoginError', 'Sorry, your credentials are incorrect.');
            redirect(base_url() . 'account/login');
          }
  
         }
  
      }
  
    public function login() {
  
      $data['title'] = &quot;Login Fool&quot;;
      $this-&gt;load-&gt;view('templates/header', $data);
      $data['contents'] = $this-&gt;load-&gt;view('login_view', NULL, TRUE);
      $this-&gt;load-&gt;view('page', $data);
      $this-&gt;load-&gt;view('templates/footer');
  
    }
  
  }
  </code></pre>
  <hr />
  <h1>login_view.php (view)</h1>
  <pre><code>&lt;h1&gt;Login Now&lt;/h1&gt;
  &lt;?php
    if(validation_errors() != false) {
      echo &quot;&lt;div id='errors'&gt;&quot; . validation_errors() . &quot;&lt;/div&gt;&quot; ;
    }
  ?&gt;
  &lt;?= ($this-&gt;session-&gt;flashdata('LoginError')) ? '&lt;p class=&quot;LoginError&quot;&gt;' . $this-&gt;session-&gt;flashdata('LoginError') . '&lt;/p&gt;' : NULL ?&gt;
  
  &lt;?php echo form_open('account/validate'); ?&gt;
     &lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;
     &lt;input type=&quot;text&quot; size=&quot;20&quot; id=&quot;username&quot; name=&quot;username&quot; value=&quot;&lt;?php echo set_value('username'); ?&gt;&quot;/&gt;
     &lt;br/&gt;
     &lt;label for=&quot;password&quot;&gt;Password:&lt;/label&gt;
     &lt;input type=&quot;password&quot; size=&quot;20&quot; id=&quot;passowrd&quot; name=&quot;password&quot; value=&quot;&lt;?php echo set_value('password'); ?&gt;&quot;/&gt;
     &lt;br/&gt;
     &lt;input type=&quot;submit&quot; value=&quot;Login&quot;/&gt;
   &lt;/form&gt;
  </code></pre>
  <p>Any ideas why the errors won't show above the form?</p>