Welcome Guest, Not a member yet? Register   Sign In
Field validation
#1

[eluser]elmne[/eluser]
If i need to validate and ensure that atleast the user must fill in one field out of 3, how do i do that?

There is an example of how to do it with two fields, but what if a user must enter atleast one of the 3 or more fields? How would that be configured?

Below is the example shown for checking that atleast one of two fields is input, but it doesn't work for 3 fields.


Code:
// If no email address, phone is required
if ( ! $this->input->post('email'))
{
$this->form_validation->set_rules('phone', 'Phone Number', 'required');
}
else
{
$this->form_validation->set_rules('phone', 'Phone Number', '');
}

// If no phone number, email is required
if ( ! $this->input->post('phone'))
{
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
}
else
{
$this->form_validation->set_rules('email', 'Email Address', 'valid_email');
}


Messages In This Thread
Field validation - by El Forum - 05-23-2010, 06:37 PM
Field validation - by El Forum - 05-24-2010, 03:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB