2009年2月24日星期二

[fw-mvc] problem with outputting tr's on element decorators

I'm trying to create a simple form using the table 'recipe' from the following devzone article(http://devzone.zend.com/article/3450-Decorators-with-Zend_Form). I'm having problems with rendering the <tr>'s in element_decorator associated elements. I'm am using ZF 1.7.0. Am I doing something wrong. I have included the class code and the outputted form. Thanks for any help!

class AdRefreshForm extends Zend_Form{
  
    public function __construct($channels){
   
    parent::__construct();
                       
        $this->setAction('/fadmin/app/ad/manage-refresh');         
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table')),
            'Form',
        ));
       
        $element_decorator=array(
                'ViewHelper',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array('Label', array('tag' => 'td'),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
            ));


        $button_decorator=array(
            'ViewHelper',
            array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
            array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        );
       

        $this->addElement('text', 'username', array(
            'decorators'=>$element_decorator,
            'label'=>'Username:',
        ));

        $this->addElement('text', 'firstname', array(
            'decorators'=>$element_decorator,
            'label'=>'First Name:',
        ));
       
        $this->addElement('text', 'lastname', array(
            'decorators'=>$element_decorator,
            'label'=>'Last Name:',
        ));
$this->addElement('submit', 'save', array(
    'decorators'=>$button_decorator,
    'label'=>'Save',
));


$submit=new Zend_Form_Element_Submit('submit');
$submit->setLabel('Update Me');
$submit->setDecorators($button_decorator);

$this->addElement($submit);
return $this;


}

It is generating the following:

<form enctype="application/x-www-form-urlencoded" action="/fadmin/app/ad/manage-refresh" method="post">
<table>
    <td><label for="username" class="optional">Username:</label></td>
    <td class="element"><input type="text" name="username" id="username" value=""></td>
    <td><label for="firstname" class="optional">First Name:</label></td>
    <td class="element"><input type="text" name="firstname" id="firstname" value=""></td>
    <td><label for="lastname" class="optional">Last Name:</label></td>
    <td class="element"><input type="text" name="lastname" id="lastname" value=""></td>
    <tr><td></td><td class="element"><input type="submit" name="save" id="save" value="Save"></td></tr>
    <tr><td></td><td class="element"><input type="submit" name="submit" id="submit" value="Update Me"></td></tr>
</table>
</form>

没有评论: