-- Dieter Provoost <[EMAIL PROTECTED]> wrote
(on Thursday, 13 March 2008, 03:43 AM -0700):
> Playing around with Zend_Form I noticed that when you want to populate a
> form, it loops over all form elements and populates them with the available
> values.
> 
> It loops all elements, including submit buttons, which are unnecessary to
> loop over.
> 
> When I populate a form, I want it to set default values for all kinds of
> fields, but not the submit buttons. (because these values aren't available
> in the data-array I provide with the populate method)
> 
> Using this populate function, on a form, the values from
> $btnSubmit->setValue('submit') get overridden and replaced by null since
> there is no key in the data-array which is the same as the submitbutton
> object name.

You must be using RC1 or earlier -- I fixed this issue in trunk last
week, and that fix is now available in RC3. populate() now only
populates the values for which it has keys.

> I suggest there should be an extra filter when looping over the different
> form elements and only set defaults on text-fields, radio buttons, ... but
> NOT on submit buttons (and maybe some other elements). Otherwise these
> buttons lose their initailly set value.
> 
> Something like this (quick & dirty) in Zend_Form, method setDefault(...):
>  if ($element = $this->getElement($name)) {
>               
>               if(!($element instanceof Zend_Form_Element_Submit))
>               {
>                       $element->setValue($value);
>               }
>         } else {...
> 
> Same thing for validation check. Should a submit button be validated??

You may want to determine if the value passed is the same as the value
stored in the submit button -- to verify that you didn't get a bogus
submission. We also use the logic internally to determine if a
particular button was used -- you can use the isChecked() method of each
button type (Submit, Reset, Button) to determine if that particular
button was used to submit the form -- this will only work *after* you've
either populated the form *or* run through validations (which populates
the form as well).

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to