[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.
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
[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.