Welcome Guest, Not a member yet? Register   Sign In
form_validation->run() not working as expected
#1

[eluser]Unknown[/eluser]
I am learning to use CI (need to use it to re-write an existing app) and have run into an issue where
Code:
form_validation->run()
doesn't work as expected. Here is the code:

Code:
<?php
class Validator extends Controller {

  function Validator()
  {

    // load controller parent
    parent::Controller();

    // load 'url' helper
    $this->load->helper('url');

    // load 'form' helper
    $this->load->helper('form');

    // load 'validation' class
    $this->load->library('form_validation');

  }

  function index()
  {

    // set validation rules
    $rules['first_name']="required|min_length[2]|max_length[20]";
    $rules['last_name']="required|min_length[2]|max_length[20]";
    $this->form_validation->set_rules($rules);

    // check if form has been submitted properly
    if ( $this->form_validation->run() == FALSE )
    {
      // redisplay web form
      $this->load->view('form_view');

    }

    // display success web page
    else
    {
      $this->load->view('success_view');
    }

  }

}
?>

The web form is displayed properly. If I enter incorrect values (or fail to enter a value) for one of the fields being validated, I expect to get an error message. Instead, the test:

Code:
if ( $form_return = $this->form_validation->run() == FALSE )
{
}

is FALSE (form_validation->run() returns TRUE). Every time. When I use validation->run() the test succeeds (validation->run() returns FALSE).

I am using CodeIgniter 1.7.2 and would like to use the Form_validation library as it lets me set custom error messages.

Is there some trick that I'm missing?

Thanks!


Messages In This Thread
form_validation->run() not working as expected - by El Forum - 01-12-2010, 07:06 PM
form_validation->run() not working as expected - by El Forum - 01-12-2010, 08:12 PM
form_validation->run() not working as expected - by El Forum - 01-12-2010, 09:31 PM
form_validation->run() not working as expected - by El Forum - 01-12-2010, 11:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB