Yes Actually.
1. Don't make the textfield required.
2. Write a custom validator for the textfield and inside the validator make
use of the extra $context parameter. $context will be an array of the
complete form values so you can check the radio button value and validate
only if it's a Yes. Otherwise return true.

Another way:
In your controller, after you instantiate the $form, and before you
validate. Just after you check if the request is POST or not. If it's POST,
examine $_POST['radio_button'] and based on that change
$form->my_textfield->setRequired() to the appropriate value.

Cheers,
- Amr

On Sat, Mar 29, 2008 at 1:25 AM, joaco182 <[EMAIL PROTECTED]> wrote:

>
> I am trying to create a form that has a set of radio buttons marked Yes
> and
> No and a text field.
>
> I would like the text field to be required only when the Yes option is
> selected for the radio's.
>
> If I attach custom validation to the radio buttons, I can get an error to
> occur like I want, but the error is displayed under the radio's instead of
> the text field.
>
> I have been unable to get any validation to work on the text field if
> isRequired is not set. Is there any way to get the validation rules setup
> so
> that the text field is only required when the condition is met? or is
> there
> a way to tell Zend_From where to display its error?
>
>
> --
> View this message in context:
> http://www.nabble.com/Conditional-Validation-tp16364221p16364221.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>

Reply via email to