• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validate rule for if both fields are empty.

#1
[eluser]boltsabre[/eluser]
Hi guys, hoping someone can point me in the correct direction here.

I have a contact form, which includes an Email Address field and a Telephone field.

Is there a way to check in my application/libraries/MY_Form_validation file for if both these fields are empty when my form validation runs?

I've had a hunt, but haven't found anything too helpful. Sorry if this is dead easy, but I'm not the worlds greatest coder (but slowly getting better). Currently I have this:

Code:
//controller function, my rule is "phone_and_email_required", applied to both 'phone' and 'email'
$this->form_validation->set_rules('phone', 'Phone Number', 'trim|min_length[6]|max_length[25]|phone_check|phone_and_email_required');
  $this->form_validation->set_rules('email', 'Email address', 'trim|valid_email|max_length[100]|phone_and_email_required');

Code:
// inside MY_Form_validation file
function phone_and_email_required($str){
  print_r('here');die();
  if($this->input->post('phone') == "" && $this->input->post('email') ==""){
   $this->CI->form_validation->set_message('phone_and_email_required', 'You must enter at least one of the Contact Details options');
   return false;
  } else{
   return true;
  }
}

But I'm not even getting into the function unless something is entered into one of the two fields first, kind of defeating the purpose of it in the first place!!!

Any thoughts???


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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