Zend Form, table decorators
Asked Answered
M

2

7

I am having an incredibly difficult time to decorate a Zend form the way I need to. This is the HTML structure I am in need of:

<table>
<thead><tr><th>one</th><th>two</th><th>three</th><th>four</th></thead>
<tbody>
<tr>
 <td><input type='checkbox' id='something'/></td>
 <td><img src='src'/></td>
 <td><input type='text' id='something'/></td>
 <td><input type='radio' group='justonegroup'/></td>
</tr>
<tr>
 <td><input type='checkbox' id='something'/></td>
 <td><img src='src'/></td>
 <td><input type='text' id='something'/></td>
 <td><input type='radio' group='justonegroup'/></td>
</tr>
</tbody>
</table>

The number of rows in the body is determined by my looping structure inside my form class. All ids will be unique of course. All radio buttons in the form belongs to one group. My issue really is that I am unsure how to create and then style the object Zend_Form_Element_MultiCheckbox and Zend_Form_Element_Radio inside my table. Where/how would I apply the appropriate decoraters to the checkboxes and radio buttons to have a form structure like above?

My Form class so far:

class Form_ManageAlbums extends Zend_Form
{
  public function __construct($album_id)
  {
    $photos = Model_DbTable_Photos::getAlbumPhotos($album_id);

    $selector = new Zend_Form_Element_MultiCheckbox('selector');

    $radio = new Zend_Form_Element_Radio('group');

    $options = array();

    while($photo = $photos->fetchObject())
    {

      $options[$photo->id] = '';

      $image = new Zend_Form_Element_Image('image'.$photo->id);
      $image->setImageValue('/dog/upload/'.$photo->uid.'/photo/'.$photo->src);

      $caption = new Zend_Form_Element_Text('caption'.$photo->id);
      $caption->setValue($photo->caption);

      $this->addElements(array($image, $caption));
    }

    $selector->addMultiOptions($options);
    $radio->addMultiOptions($options);

    $this->addElement($selector);

  $this->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'table')),
        'Form'
    ));
  }
}

I have tried a few combination of decoraters for the td and tr, but no success to date.

Thank you for any help, very appreciated. JP Levac

Misdate answered 28/10, 2009 at 14:38 Comment(0)
P
11

Here is a tutorial for creating table layout with zend form decorators: Tutorial - Create Zend Framework Form with table layout using decorators

Pinky answered 10/8, 2010 at 7:18 Comment(0)
M
4

Take a look at this devzone article. It'll explain how decorators work, so you know what's happening and how to write your own, and then finishes with a table example.

There's some good explanation of decorators by the author of Zend_Form in these two articles:

Magus answered 30/10, 2009 at 23:19 Comment(1)
@KevinPeno it looks like Zend have a new website. The formatting is broken but take a look at this updated page. I've updated the original post.Magus

© 2022 - 2024 — McMap. All rights reserved.