Just a reply for others... After some sleep I realised the best way to
do this was with a single setPostValidator which called a single
sfValidatorCallback to validate all 5 fields... Inside the callback
class, I tested for the existence of each field (by checking the array
of form values submitted with array_key_exists), then validated it if
it was there...
It just has a single error message at the top of the page which says
something along the lines of "one of these fields are required for
each set of data"... not perfect, I'd like to have the error where the
fields are, but it does the job ok.
On Oct 28, 6:20 pm, John Masson <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---