It appears that checkboxes need to set a couple of public properties before
rendering

$newsletterOptin->options = array(
    'checked' => $newsletterOptin->getCheckedValue(),
    'unChecked' => $newsletterOptin->getUncheckedValue()
);

Kinda nasty. It's probably nicer to use the decorators the usual way for
checkboxes instead.

   -- Mon


On Sat, Mar 7, 2009 at 2:55 AM, <[email protected]> wrote:

>  Hi all,
>
> With my Zend_Form I'm populating a single optin checkbox. After submission,
> when the form is not valid and is rerendered, it fails to have remembered
> the checkbox's state. It seems to populate a default value of "0" in the
> hidden element (which I think is correct) but also in the checkbox input
> element as well.
>
>   $newsletterOptin = new Zend_Form_Element_Checkbox( 'newsletterOptin' );
>   $newsletterOptin->setDecorators( $decorators )
>   ->setLabel( 'Yes, I want to subscribe to your newsletter' )
>   ->setAttribs( array( 'value' => '1' ) );
>
>
> I tried the following, but all to no avail:
>
> ->setCheckedValue( 1 )
> ->setCheckedValue( "1" )
> ->setValue( 1 )
> ->setValue( "1" )
> ->setAttribs( array( 'value' => '1' ) )
>
> To populate the checkbox I vahe the following code in my ViewScript:
>
> <dd>
>  <?= $form->newsletterOptin->renderViewHelper(); ?> <?=
> $form->newsletterOptin->renderLabel(); ?>
> </dd>
>
>
>
> Any idea of what is going on here? Thanks.
>
> ------------------------------
> Deel en publiceer je favoriete foto's met Windows Live 
> Photos<http://windowslive.microsoft.nl/WL/Explore/Photos>
>

Reply via email to