title: CodeIgniter form validation always return false
body: <p>I've been scouring the webs and potching with my code for hours now and can't seem to figure out why this isn't working.</p>
  
  <p>I have a template library which scans a template.html for {@tags} and then runs the function associated to the tag to create data for that {@tag}'s content and then replaces {@tag} for the content generated, so I can have widget like parts to my template.</p>
  
  <p>On my account/access page I have a login form and a registration form, now when the template library calls the widget_register() function, the form validation doesn't seem to do anything,   the data is posted as I can see from the profiler, but the form validation doesn't seem to do anything with it</p>
  
  <h2>Account Controller</h2>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Account extends CI_Controller {
  
  public function index()
  {
      $this-&gt;load-&gt;helper('url');
      #redirect('/');
  }
  
  public function access()
  {
      $this-&gt;load-&gt;helper('url');
  
      #if($this-&gt;auth-&gt;loggedin()) redirect('/');
  
      $this-&gt;template-&gt;compile_page();
  }
  
  public function widget_register($template)
  {
      $this-&gt;output-&gt;enable_profiler(TRUE);
  
      $this-&gt;load-&gt;helper('url');
  
      if($this-&gt;auth-&gt;loggedin()) redirect('/');
  
      if ($this-&gt;input-&gt;post('register_submit'))
      {
          $this-&gt;load-&gt;model('auth_model');
  
          $this-&gt;form_validation-&gt;set_rules('register_nickname', 'Nickname', 'required|min_length[3]|max_length[75]');
          $this-&gt;form_validation-&gt;set_rules('register_email_address', 'Email Address', 'required|valid_email|is_unique[users.email]');
          $this-&gt;form_validation-&gt;set_rules('register_confirm_email_address', 'Confirm Email Address', 'required|valid_email|matches[register_email_address]');
          $this-&gt;form_validation-&gt;set_rules('register_password', 'Password', 'required|min_length[5]');
          $this-&gt;form_validation-&gt;set_rules('register_confirm_password', 'Confirm Password', 'required|min_length[5]|matches[register_password]');
  
          if($this-&gt;form_validation-&gt;run() !== false)
          {
  
              echo 'validation successful';
              $nickname = $this-&gt;input-&gt;post('register_nickname');
              $email = $this-&gt;input-&gt;post('register_email_address');
  
              $generate_salt = $this-&gt;auth-&gt;generate_keys();
  
              $salt = $generate_salt['1'];
  
              $this-&gt;load-&gt;library('encrypt');
  
              $generate_password =  $salt . $this-&gt;input-&gt;post('register_password');
              $password = $this-&gt;encrypt-&gt;hash($generate_password);
  
              $generate_series_key = $this-&gt;auth-&gt;generate_keys();
              $user_series_key = $generate_series_key['1'];
  
              $this-&gt;db-&gt;query('INSERT INTO users (nickname, email, password, salt, register_date) VALUES ( "'.$nickname.'", "'.$email.'", "'.$password.'", "'.$salt.'", "'.time().'")');
          }
          else
          {
              echo 'invalid';
              echo validation_errors();
          }
      }
  
      $this-&gt;load-&gt;helper('form');
  
      $view_data = array();
      $view_data['form'] = form_open('account/access');
      $view_data['input_nickname'] = form_input(array('name' =&gt; 'register_nickname', 'value' =&gt; set_value('register_nickname'), 'id' =&gt; 'register_nickname', 'class' =&gt; 'common_input', 'size' =&gt; '55'));
      $view_data['input_email'] = form_input(array('name' =&gt; 'register_email_address', 'value' =&gt; set_value('register_email_address'), 'id' =&gt; 'register_email_address', 'class' =&gt; 'common_input', 'size' =&gt; '55'));
      $view_data['input_confirm_email'] = form_input(array('name' =&gt; 'register_confirm_email_address', 'value' =&gt; '', 'id' =&gt; 'register_confirm_email_address', 'class' =&gt; 'common_input', 'size' =&gt; '55'));
      $view_data['input_password'] = form_password(array('name' =&gt; 'register_password', 'value' =&gt; '', 'id' =&gt; 'register_password', 'class' =&gt; 'common_input', 'size' =&gt; '55'));
      $view_data['input_confirm_password'] = form_password(array('name' =&gt; 'register_confirm_password', 'value' =&gt; '', 'id' =&gt; 'register_confirm_password', 'class' =&gt; 'common_input', 'size' =&gt; '55'));
      $view_data['form_submit'] = form_submit('register_submit', 'Register');
      $view_data['/form'] = form_close();
      $view_data['validation_errors'] = validation_errors('&lt;div class="error-box"&gt;', '&lt;/div&gt;');
  
  
      return $this-&gt;parser-&gt;parse(FCPATH.'themes/'.$this-&gt;settings-&gt;settings['system_settings']['theme'].'/widgets/'.$template.'.html', $view_data, TRUE);
  
  }
  
  function widget_login()
  {
      $this-&gt;load-&gt;helper('url');
  
      // user is already logged in
  
      if ($this-&gt;auth-&gt;loggedin())
      {
          return $this-&gt;load-&gt;view(FCPATH.'themes/'.$this-&gt;settings-&gt;settings['system_settings']['theme'].'/widgets/login/user.html', '', TRUE);
      }
  
      if($this-&gt;input-&gt;post('register'))
      {
          redirect('authentication/register');
      }
  
      // form submitted
  
      if ($this-&gt;input-&gt;post('login_email_address') &amp;&amp; $this-&gt;input-&gt;post('login_password'))
      {
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;load-&gt;model('auth_model');
  
          $this-&gt;form_validation-&gt;set_rules('login_email_address', 'Email Address', 'required|valid_email');
          $this-&gt;form_validation-&gt;set_rules('login_password', 'Password', 'required|min_length[4]');
  
          if($this-&gt;form_validation-&gt;run() !== false)
          {
              // validation passed verify from db
  
              $remember = $this-&gt;input-&gt;post('remember') ? TRUE : FALSE;
  
              if($remember == 'remember');
  
              // check user exists and return user data
  
              $user_data = $this-&gt;auth_model-&gt;user_exists($this-&gt;input-&gt;post('email_address'), TRUE);
  
              if($user_data != FALSE)
              {
                  // compare passwords
  
                  if ($this-&gt;auth_model-&gt;check_password($this-&gt;input-&gt;post('password'), $this-&gt;input-&gt;post('email_address')))
                  {
                      $this-&gt;auth-&gt;login($user_data-&gt;uid, $remember);
                      redirect('/');
                  }
                  else { $this-&gt;form_validation-&gt;set_custom_error('Incorrect password'); }
              }
              else { $this-&gt;form_validation-&gt;set_custom_error('There are no users with that email address'); }
          }
      }
  
      // show login form
  
      $this-&gt;load-&gt;helper('form');
  
      $view_data = array();
      $view_data['form'] = form_open();
      $view_data['input_email'] = form_input('login_email_address', set_value('login_email_address'), 'id="login_email_address"');
      $view_data['input_password'] = form_password('login_password', '', 'id="login_password"');
      $view_data['input_remember'] = form_checkbox('remember', 'rememberme');
      $view_data['form_submit'] = form_submit('login_submit', 'Login');
      $view_data['register_button'] = form_submit('register', 'Register');
      $view_data['/form'] = form_close();
      $view_data['validation_errors'] = validation_errors('&lt;div class="error-box"&gt;', '&lt;/div&gt;');
  
      return $this-&gt;parser-&gt;parse(FCPATH.'themes/'.$this-&gt;settings-&gt;settings['system_settings']['theme'].'/widgets/login/login.html', $view_data, TRUE);
  }
  
  function logout()
  {   
      $this-&gt;load-&gt;helper('url');
      $this-&gt;session-&gt;sess_destroy();
  
      $this-&gt;load-&gt;helper('cookie');
      delete_cookie('aws_session');
      delete_cookie('aws_autologin_cookie');
  
      redirect('/');
  }
  }
  </code></pre>
  
  <h2>and the Template library</h2>
  
  <p>
  
  <pre><code>class Template {
  
  private $settings;
  private $_ci;
  private $_controller = ''; # Controller in use
  private $_method = ''; # Method in use
  private $_is_mobile = FALSE; # Is the User agent a mobile?
  private $cache_lifetime = '1';
  
  private $page_output = "";
  private $partials = array();
  private $spts = array(); # Static page tags
  
  function __construct()
  {
      $this-&gt;_ci =&amp; get_instance();
      $this-&gt;settings = $this-&gt;_ci-&gt;settings-&gt;settings;
  
      $this-&gt;_controller = $this-&gt;_ci-&gt;router-&gt;fetch_class();
      $this-&gt;_method = $this-&gt;_ci-&gt;router-&gt;fetch_method();
  
      $this-&gt;_ci-&gt;load-&gt;library('user_agent');
      $this-&gt;_is_mobile = $this-&gt;_ci-&gt;agent-&gt;is_mobile();
  
      log_message('debug', "Template Class Initialized");
  }
  
  function build_page()
  {
      $page = $this-&gt;_ci-&gt;load-&gt;view(FCPATH.'themes/'.$this-&gt;settings['system_settings']['theme'].'/pages/'.$this-&gt;settings['page_settings']['template'].'.html', '', TRUE);
  
      $this-&gt;page_output .= $page;
  }
  
  # MAIN PAGE FUNCTIONS END ------------------------------------------------------------------------------------------
  
  public function check_static_tags()
  {
      if(preg_match_all('/{@[A-Z]{1,75}}/', $this-&gt;page_output, $matches))
      {
          $this-&gt;spts = $matches['0'];
          $this-&gt;spts = array_diff($this-&gt;spts, array('{@CONTENT}')); # removes stp_content from array list
  
          return TRUE;
      }
      return FALSE;
  }
  
  # Convert static tags
  
  public function convert_static_tags()
  {
      foreach($this-&gt;spts as $key =&gt; $static_tag)
      {
          $static_tag = str_replace(array('{','}'), '', $static_tag);
          $this-&gt;partials[$static_tag] = $this-&gt;build_widget($static_tag);
      }
  }
  
  # Convert widget tags
  
  function column_widget_tags()
  {
      if(preg_match_all('/{@COLUMN_[0-9]{1,11}}/', $this-&gt;page_output, $matches))
      {
          if(isset($this-&gt;settings['page_settings']['widgets']))
          {
              $columns = unserialize($this-&gt;settings['page_settings']['widgets']);
          }
  
          foreach($columns as $column_id =&gt; $widgets)
          {
              if(count($columns[$column_id]) &gt; '0') // if the column contains widgets
              {
                  $this-&gt;partials[''.$this-&gt;_stp.'_COLUMN_'.$column_id] = '';
  
                  foreach($widgets as $key =&gt; $widget_id)
                  {
                      // build the widget and add it to the $this-&gt;page_bits['column_id'] variable for replacing later in the compiler
  
                      $this-&gt;partials[''.$this-&gt;_stp.'_COLUMN_'.$column_id] .= $this-&gt;build_widget($widget_id);
                  }
              }
              else
              {
                  $this-&gt;partials[''.$this-&gt;_stp.'_COLUMN_'.$column_id] = '';
              }
          }
      }
  }
  
  # Build Widget
  
  function build_widget($widget_id)
  {
      if(is_numeric($widget_id))
      {
          $widget_query = $this-&gt;_ci-&gt;db-&gt;query('SELECT * FROM widgets WHERE id = "'.$widget_id.'"'); # BIND STATEMENTS
      }
      elseif(preg_match('/@[A-Z]{1,75}/', $widget_id))
      {           
          $widget_query = $this-&gt;_ci-&gt;db-&gt;query('SELECT * FROM widgets WHERE tag = "'.$widget_id.'"'); # BIND STATEMENTS
      }
      else
      {
          show_error('Could not get widget from database: '.$widget_id);
      }
  
      if($widget_query-&gt;num_rows() &gt; 0)
      {
          $widget_info = $widget_query-&gt;row_array();
  
          // loads widgets parent controller, builds the widget (class method) and returns it
  
          $this-&gt;_ci-&gt;load-&gt;controller($widget_info['controller'], $widget_info['controller']);
          $method_name = 'widget_'.$widget_info['method'];
          $complete_widget = $this-&gt;_ci-&gt;$widget_info['controller']-&gt;$method_name($widget_info['template']);
  
          return $complete_widget;
      }
      else
      {
          show_error('The requested widget could not be loaded: '.$widget_id);
      }
  }
  
  # Replace Partials
  
  function replace_partials()
  {   
      $this-&gt;_ci-&gt;load-&gt;library('parser');
      $this-&gt;page_output = $this-&gt;_ci-&gt;parser-&gt;parse_string($this-&gt;page_output, $this-&gt;partials, TRUE);
  }
  
  ## METADATA
  
  public function prepend_metadata($line)
  {
      array_unshift($this-&gt;_metadata, $line);
      return $this;
  }
  
  
  # Put extra javascipt, css, meta tags, etc after other head data
  
  public function append_metadata($line)
  {
      $this-&gt;_metadata[] = $line;
      return $this;
  }
  
  # Set metadata for output later
  
  public function set_metadata($name, $content, $type = 'meta')
  {
      $name = htmlspecialchars(strip_tags($name));
      $content = htmlspecialchars(strip_tags($content));
  
      // Keywords with no comments? ARG! comment them
      if ($name == 'keywords' AND ! strpos($content, ','))
      {
          $content = preg_replace('/[\s]+/', ', ', trim($content));
      }
  
      switch($type)
      {
          case 'meta':
              $this-&gt;_metadata[$name] = '&lt;meta name="'.$name.'" content="'.$content.'" /&gt;';
          break;
  
          case 'link':
              $this-&gt;_metadata[$content] = '&lt;link rel="'.$name.'" href="'.$content.'" /&gt;';
          break;
      }
  
      return $this;
  }
  
  # Embed page into layout wrapper
  
  function layout()
  {
      $this-&gt;_ci-&gt;load-&gt;helper('html');
  
      $this-&gt;append_metadata(link_tag('themes/'.$this-&gt;settings['system_settings']['theme'].'/css/layout.css')); # default stylesheet
      $this-&gt;append_metadata('&lt;link rel="shortcut icon" href="/favicon2.ico" /&gt;'); # default favicon
  
      $template['template.title'] = $this-&gt;settings['page_settings']['title']; # Page title, can be overidden by the controller ?
      $template['template.metadata']  = implode("\n\t\t", $this-&gt;_metadata); # Metadata
      $template['template.body'] = $this-&gt;page_output; # The page
  
      return $this-&gt;_ci-&gt;parser-&gt;parse(FCPATH.'assets/layout/L6_layout_wrapper.html', $template, TRUE);
  }
  
  # Run all functions to build page and set in output class
  
  function compile_page($content_data = '')
  {
      $this-&gt;partials['@CONTENT'] = $content_data;
  
      $this-&gt;build_page();
  
      $this-&gt;column_widget_tags();
  
      if($this-&gt;check_static_tags())
      {
          $this-&gt;convert_static_tags();
          $this-&gt;replace_partials();
      }
  
      $output = $this-&gt;layout();
  
      $this-&gt;_ci-&gt;output-&gt;set_header('Expires: Sat, 01 Jan 2000 00:00:01 GMT');
      $this-&gt;_ci-&gt;output-&gt;set_header('Cache-Control: no-store, no-cache, must-revalidate');
      $this-&gt;_ci-&gt;output-&gt;set_header('Cache-Control: post-check=0, pre-check=0, max-age=0');
      $this-&gt;_ci-&gt;output-&gt;set_header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
      $this-&gt;_ci-&gt;output-&gt;set_header('Pragma: no-cache');
  
      # Let CI do the caching instead of the browser
      #$this-&gt;_ci-&gt;output-&gt;cache($this-&gt;cache_lifetime);
  
      $this-&gt;_ci-&gt;output-&gt;append_output($output);
  }
  }
  </code></pre>
  
  <p>Sorry for the incredibly long post, I'm really stumped here and didn't want to miss any code out, thanks in advance!</p>