Welcome Guest, Not a member yet? Register   Sign In
ssn/phone validation
#1

[eluser]browntown[/eluser]
When collecting data from a user I like to split the phone and ssn fields into three separate fields. A drawback of this is that my error string always contains something like:

phone(1) is required
phone(2) is required
phone(3) is required

where I'd really just like to display something like

"please enter your full 9 digit phone number."

is there a way I can programatically assign one error message to three fields?
#2

[eluser]Michael Wales[/eluser]
Code:
$rules['phone1'] = 'callback__check_phone';

function _check_phone($phone1) {
    $phone2 = $this->input->post('phone2');
    $phone3 = $this->input->post('phone3');

    if ((!$phone1) && (!$phone2) && (!$phone3)) {
        $this->validation->set_message('_check_phone', 'Please enter your full 9-digit phone number.');
        return FALSE;
    } else {
        return TRUE;
    }
}

Of course, this doesn't validate the format of the inputs - I would use RegEx for that (in combination with the numeric validation rule).
#3

[eluser]browntown[/eluser]
sweet...i'll give that a go.

thanks.
#4

[eluser]browntown[/eluser]
so the only field that would be required would be the first phone field? The rest I would check within the callback?
#5

[eluser]Michael Wales[/eluser]
Correct. If you place the required notice on all 3 fields you will get multiple errors - this way, we're still checking to make sure all 3 fields are required, but we're only doing that from one location (the callback) and we can also define a much nicer error message.




Theme © iAndrew 2016 - Forum software by © MyBB