• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick Question - How to clear the form validation rules and errors?

#3
[eluser]mlakhara[/eluser]
Thanks for your prompt reply. I am trying to achieve a form based authentivation in which username or email can be used. I am using form_validation to check if the user entered an email or just username. after that I am setting validation for them seperately.

Code:
$this->form_validation->set_rules('username','Username','valid_email');
  if($this->form_validation->run() == FALSE)
  {
   /*Reset the varibales used in form_validtion class
   $this->form_validation->_field_data = array();
      $this->form_validation->_config_rules = array();
      $this->form_validation->_error_array = array();
        $this->form_validation->_error_messages = array();
        $this->form_validation->error_string = '';
   //Username used for authentication*/
   unset($this->form_validation);
   $this->load->library('form_validation');
   $this->form_validation->set_rules('username','Username','require|max_length[35]');
  }
  else
  {
   /*Reset the varibales used in form_validtion class
   $this->form_validation->_field_data = array();
      $this->form_validation->_config_rules = array();
      $this->form_validation->_error_array = array();
        $this->form_validation->_error_messages = array();
        $this->form_validation->error_string = '';
   //Email supplied for authentication*/
   unset($this->form_validation);
   $this->form_validation->set_rules('username','Username',"require|max_length[35]|is_unique('user.email')|valid_email");
   $this->_email == TRUE;
  }

I tried to use your approach but then I am unable to use the validation again.
getting the following error.
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Account::$form_validation

Filename: controllers/account.php

Line Number: 61

Fatal error: Call to a member function set_rules() on a non-object in C:\xampp\htdocs\cosys\cosys_initial\trunk\application\controllers\account.php on line 61


Messages In This Thread
Quick Question - How to clear the form validation rules and errors? - by El Forum - 07-12-2012, 07:56 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.