Hi guys,

I'm working with sf1.1 since quite some time now and I have to say
that the form system is really, really great. With some of the
tutorials out there (e.g. thatsquality.com), I was able to digg deeply
into its inner workings and get things done. But there is something I
just can't figure out:

In short: I want a field to be validated only depending on the input
in another field.

Imagine a form, where a user can choose between two payment options:
bank transfer and credit card (e.g. sfWidgetFormSelectRadio). This
selection wil activate the validators for the relevant fields which
are all required:
Bank Transfer: bank name, account name, BIC/IBAN
OR
Credit Card: card organization, card number, expiry date

On the view side, the relevant fields would be hidden and shown via
JavaScript. But the widgets have to be there in the HTML, so they have
to be created in the action. If there is no special form processing/
validation, submitting the form will always fail because some required
fields would always be empty.

Searching on google and asking in #symfony hinted me at using
postValidator. But I couldn't figure out how to do it that way. There
are several disadvantages with postValidator, as I think:
- I can only access values in the current form, but would do you do if
you have forms, embedded in forms?
- I have to use the postValidator on the first widget (e.g. payment
option) and add the validators of the dependant widgets (e.g. bank
transfer or credit card). But what do you do, if you have several
dependancies?

I came up with my own solution to this problem, but I think it's the
worst possible solution there is. I created my own form class
extending sfForm, which has a method activateValidators(). All
validators in this class are stored temporarily in an array (and not
directly in $this->validatorSchema). In the action, in the process of
creating the forms, I check for the dependencies and call
activateValidators() if needed. The method activateValidators() will
copy the validators from my temporary array to $this->validatorSchema,
thus finally making the validators active.

The problem here is, that I work on the parameters directly, without
having them validated/cleaned yet, because I'm in the process of
building the form. Altough I would wish to have them already validated
or cleaned.

Is there a better way to solve this? Is there a symfony way of doing
this? Please help me out. Also I think this is a common thing and
Symfony 1.1 really should support this.

Regards,
Axel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to