Sorry guys, forgot to send to [email protected]. So here you go: 

From: [email protected]
To: [email protected]
Subject: RE: [fw-general] Zend_Form: MultiCheckbox or Checkbox i.c.w.   
ViewScript and looping through individual elements
Date: Fri, 6 Mar 2009 15:58:00 +0000










Date: Fri, 6 Mar 2009 18:26:25 +0800
From: [email protected]
To: [email protected]
Subject: Re: [fw-general] Zend_Form: MultiCheckbox or Checkbox i.c.w.   
ViewScript and looping through individual elements

1. My suggestion is to take the string output of 
$multiCheckbox->renderViewHelper(), explode it using the separator, then loop 
through each line. e.g.

$form->addElement('multiCheckbox', 'foo', array(

    'multiOptions' => $options, 
    'separator' => '__SEPARATOR__'
));// view script
$output = $this->element->renderViewHelper();$lines = explode('__SEPARATOR__', 
$output);

$c = 0;
foreach ($lines as $line) {    echo $line . (++$c % 3 == 0 ? '<br />' : '');
}Just make sure that you use a unique separator that won't cause the string to 
split incorrectly.

2. If it's for rendering the form tag, <?php echo $form->renderForm(false) ?> 
would output the opening <form> tag complete with the form attributes.

    -- Mon


Hi Mon,

1) Good suggestion, seems like this is the way to go, yes. Thanks.

2) Yes! I was looking for something like that. But couldn't find it in de 
apidoc nor in the Zend_Form class itself. Now I realize it is a decorator being 
called through the magic __call() method. So I tried it just now, but couldn't 
get it to work at first, but now I realize this was due to the fact that I had 
overwritten the standard decorators with:

$this->setDecorators( array(
                                        'PrepareElements',
                                        array( 'ViewScript', array( 
'viewScript' => 'offer/partials/form.phtml' )
);


Now that I added                                        'Form' as the first 
element in the argument array all works fine.
Once again thank you for your valuable input. Zend Frameworks community is ace! 
:-)

Cheers



On Fri, Mar 6, 2009 at 5:19 AM,  <[email protected]> wrote:






Hi y'all,

I'm using a ViewScript decorator for my Zend_Form. In this form I'ld like each 
third checkbox in a collection of checkboxes to start on a newline, or in a new 
block element or something similar. I tried it with a MultiCheckbox.


I wish I could do something similar as beneath in my forms ViewScript:
<? 
$c = 1;
foreach( $this->element->myMultiCheckbox as $checkbox )
{
  $separator = $c % 2 == 0 ? '<br>' : '';

  echo $checkbox->renderViewHelper() . $separator;
  $c++;
}
?>

But sadly this doesn't seem possible. My next option I think would be to use 
seperate Checkbox elements with the multiple [] indicator in their names. But I 
have no idea how I would be able to loop through them in my ViewScript either. 
Do you perhaps have any hints on how I could achieve this?


Also, with the Zend_Form ViewScript decorator, I thought I would be able to 
access the form object with something like $this->form from within the view. 
But I'm not able to access it. How would I be able to access for instance 
Zend_Form::getMethod(), Zend_Form::getEncType() and other (userland) attributes 
from within the ViewScript?


Thank you for your pointers.


Plan je feest, nodig mensen uit en deel je foto's met Windows Live Events


Deel en publiceer je favoriete foto's met Windows Live Photos
_________________________________________________________________
Haal meer uit je leven met Windows Live
http://windowslive.microsoft.nl/WL/Home

Reply via email to