Zend Form, table decorators

13,633

Solution 1

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

Solution 2

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:

Share:
13,633
levacjeep
Author by

levacjeep

Java Developer - I type on the keyboard.

Updated on August 07, 2022

Comments

  • levacjeep
    levacjeep over 1 year

    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

  • David Snabel-Caunt
    David Snabel-Caunt over 12 years
    @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.