title: CodeIgniter form validation using session variables
body: <p>How do I get the CodeIgniter form validation to validate the <code>$_SESSION</code> if there is no passed form data? I tried manually setting the <code>$_REQUEST</code> variable, but it doesn't seem to work.</p>
  
  <p>i.e. I have a function <code>search</code> in the controller which validates the form input passed, and either returns you to the previous page with errors, or else moves you onto the next page. But I want this function to also work if you previously filled out this page, and the info is stored in the <code>$_SESSION</code> variable.</p>
  
  <pre><code>function search () {
      $this-&gt;load-&gt;library("form_validation");
      $this-&gt;form_validation-&gt;set_rules("flightID", "Flight Time", "required|callback_validFlightID");
      $this-&gt;form_validation-&gt;set_rules("time", "Flight Time", "required|callback_validFlightTime");
  
      $this-&gt;setRequest(array("flightID", "time"));
  
      // adding session check allows for inter-view navigation
      if ($this-&gt;form_validation-&gt;run()) {
  
          // some application logic here
  
          $this-&gt;load-&gt;view("seats", $data);
      } else {
          $this-&gt;logger-&gt;log($_REQUEST, "request");
          // redirect back to index
          $this-&gt;index();
      }   
  }
  function setRequest () {
      // make sure none of the parameters are set in the request
      foreach ($vars as $k) {
          if (isset($_REQUEST[$k])) {
              return;
          }   
      }   
  
      foreach ($vars as $k) {
          if (isset($_SESSION[$k])) {
              $_REQUEST[$k] = $_SESSION[$k];
          }   
      }   
  
  }
  </code></pre>