I am doing codeigniter validation for email id. I have declared 3 text box for entering email id. I am retrieving all the 3 email id's in array called ref_email. now I want to do email id validation only when email id text boxes are not empty and show error message in view page. if email id text boxes are empty, then i don't want to do any validation. I don't know where i have done mistake in my code.
My controller code:
$ref_email_array=$this->input->post('ref_email');
foreach($ref_email_array as $key => $r_email ){
if ($r_email!="") {
$this->form_validation->set_rules('ref_email['.$key.']', 'Email','trim|valid_email');
$this->form_validation->set_error_delimiters('<div class="error_user" style="color:red">', '</div>');
}
}
if($this->form_validation->run()){ // insertion code }
can anybody help me? thanks in advance.