Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Symfony 1.1 Forms - how to validate a field only depending on input in another field?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Axel Baumgartner  
View profile  
 More options Mar 26 2008, 6:37 am
From: Axel Baumgartner <ignoz...@gmail.com>
Date: Wed, 26 Mar 2008 03:37:28 -0700 (PDT)
Local: Wed, Mar 26 2008 6:37 am
Subject: Symfony 1.1 Forms - how to validate a field only depending on input in another field?
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »