Hi All,
I've spent the day working on the problem of validating two fields to
ensure one of the two has been filled in. I don't mind if the user
fills in both, I just one at least one completed, not both blank.
I got this working nicely with a sfValidatorCallback inside of a
setPostValidator, however when I went to repeat this for multiple
fields on the same page (there can be up to 5 sets of the same fields
depending on what the user has selected previously) I realised that
essentially only the last of the set got validated...
So I turned to trying to get this working with an sfValidatorCallback
on one of the two fields. The problem here though is that when the
user leaves the field blank, no error checking is done at all... I
also tried with the sfValidatorCallback inside a sfValidatorAnd, but
this too failed
Is there any way to 'force' the error checking of a field even though
it's blank?? Do I need to perhaps use a setPostValidator to trigger
off these individual callbacks?
I've pasted some code below, in this case where I was trying with the
sfValidatorAnd.
Any assistance greatly appreciated...
The validator:
$this->validatorSchema['Account # 5'] = new sfValidatorAnd(
array(
new sfValidatorString(array('min_length' => 2,
'required' => false)),
new sfValidatorCallback(array('callback' =>
array('customValidator_5', 'execute'), 'arguments' => array()),
array('invalid' => 'Error Message #5')),
)
);
The validation Class:
class CustomValidator_5
{
public static function execute($oValidator) {
//get the values entered for the customer account num and dob
fields
$req = sfContext::getInstance()->getRequest()-
>getParameter('orderThree');
$current_account = $req['Account # 5'];
$customer_dob = $req['Customer DOB 5'];
//If both are blank, throw error
if($current_account == '' && $customer_dob['day'] =='' &&
$customer_dob['month'] =='' && $customer_dob['year'] =='') {
throw new sfValidatorError($oValidator, 'invalid');
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---