Welcome Guest, Not a member yet? Register   Sign In
Validation Question
#1

[eluser]LifeSteala[/eluser]
Hey guys - trying to validate a registration form which works but what I want it to do does not. The form accepts a home phone and a cell phone. Either one of those fields must be filled so I've created a callback function but I always get "Field is required!".

Code:
// Set Validation Rules
$rules['phone']      = "trim|required|callback__phoneCheck";
$this->validation->set_rules($rules);

// Callback Function
// Function: phoneCheck - Private
// Check to see if phone or mobile is entered
//-----------------------------------------------------------
function _phoneCheck($number)
{
if ( $this->input->post('phone') != "" && $this->input->post('mobile') != "" )
return false;
else
return true;
}

I figured if both values are empty then return false.. Any ideas?

Thanks!
#2

[eluser]Colin Williams[/eluser]
Quote:Either one of those fields must be filled

So, requirement is conditional. Sounds like you need a conditional IF construct:

Code:
if ( ! $this->input->post('cell'))
{
  $rules['phone'] = "trim|required|callback__phoneCheck";
}
else
{
  $rules['cell'] = "trim|required|callback__phoneCheck";
}
#3

[eluser]LifeSteala[/eluser]
Gosh - I don't know what I was thinking the other day! I should have thought of that. Anyway, thanks Colin, worked like wonders! Smile




Theme © iAndrew 2016 - Forum software by © MyBB