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
Here is a tutorial for creating table layout with zend form decorators: Tutorial - Create Zend Framework Form with table layout using decorators
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With