Hi I am trying to validate a user registration form using codeigniter form validation class. In my form majority of the fields are validated using codeigniter form validation class. But one field 'email' field has to be validated via database whether the email entered by the user is available for registration or not. When I use callback function other field validations like required|trim|xss_clean|valid_email etc don't work.
I don't want to write code manually for each of the validation like valid_email that are already exist in CI. When I use callback function for this field the CI form validations don't apply. Here is my code:
My Form:
<input type="text" name="first_name"/>
<input type="text" name="last_name"/>
<input type="text" name="email"/>
<input type="password" name="password"/>
<input type="password" name="cpassword"/>
Here is my controller:
$this->form_validation->set_rules('first_name','First Name','required|trim|xss_clean');
$this->form_validation->set_rules('last_name','Last Name','required|trim|xss_clean');
$this->form_validation->set_rules('email','Email','valid_email|xss_clen|required|callback_email_check');
$this->form_validation->set_rules('password','Password','required|min_length[6]|max_length[20]|trim|xss_clean');
$this->form_validation->set_rules('cpassword','Retype Password','callback_password_match');
My callback function for email_check:
public function email_check()
{
$email=$this->input->post('email');
if($this->home_mod->email_available($email))
{
$this->form_validation->set_message('email_check', 'Another user with this email is already registered. Please try different email');
return FALSE;
}
}
Now after all that, form validation rules valid_email|required etc don't apply. What am I doing wrong?
is_unique
to useis_unique[table_name.table_column_name]
– tomexsans