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

#1
[eluser]mlakhara[/eluser]
How to clear the form validation rules and errors?

Thanks in advance

#2
[eluser]Jason Hamilton-Mascioli[/eluser]
Without knowing exactly what you are doing you can try to unset validation

Code:
if ($this->validation->run() == TRUE) {
   //... All you code here...

   //... At the end unset validation
   unset($this->validation)
}

#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

#4
[eluser]Aken[/eluser]
There's no need to do all that extra stuff for such a simple form. Just check the database to see if the email exists first, and then if not, check for the username. If neither exist, throw an error. If one exists, that's the user you'll check against.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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