2009年3月17日星期二

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

Could you provide an example of what you are saying. I've tried just about every combination I can think of an it's not working. Forgive me but I'm new to the world of ZF.




Matthew Weier O'Phinney wrote:
-- Lionel Morrison <lionel@morrison101.com> wrote (on Tuesday, 17 March 2009, 04:43 PM -0400):   
Does anyone happen to know how to format the ReCapature element with TR TD tags. Below is a sample of my form page.      public $captchaDecorators = array(        'Errors',        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),        array(array('row' => 'HtmlTag'), array('tag' => 'tr')),    );     
 Add a 'Captcha' decorator to the top of the above list.    
       $this->addElement('captcha', 'captcha', array(            'required'   => true,            'captcha' => array('captcha' => 'ReCaptcha', 'privKey' => ' {$myprivkey}', 'pubKey' => '{$mypubkey}'),            'decorators'=>$this->captchaDecorators,        ));  Thanks Lionel        Matthew Weier O'Phinney wrote:      -- water <zflist@yahoo.com> wrote     (on Tuesday, 24 February 2009, 12:41 PM -0800):           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!       I found several issues with the code you attached.      First off, it's better to override the init() method than the     __construct() method. As it was, the signature you had for __construct()     immediately raised an error as it did not follow that used by Zend_Form.      Second, when using decorator aliasing (e.g., array('data' =>     'HtmlTag')), you should use an assoc array for the decorator, with the     keys "decorator" and "options"; this methodology eliminates errors due     to argument order.      I've reworked the class you attached as follows, and it works perfectly:          class AdRefreshForm extends Zend_Form         {              public function init()             {                 $this->setAction('/fadmin/app/ad/manage-refresh');                 $this->setDecorators(array(                     'FormElements',                     array('HtmlTag', array('tag' => 'table')),                     'Form',                 ));                  $element_decorator=array(                         'ViewHelper',                         'Errors',                         array('decorator' => array('data' => 'HtmlTag'), 'options' => array('tag' => 'td', 'class' => 'element')),                         array('Label', array('tag' => 'td')),                         array('decorator' => array('row' => 'HtmlTag'), 'options' => array('tag' => 'tr')),                     );                   $button_decorator=array(                     'ViewHelper',                     array('decorator' => array('data' => 'HtmlTag'), 'options' => array('tag' => 'td', 'class' => 'element')),                     array('decorator' => array('label' => 'HtmlTag'), 'options' => array('tag' => 'td', 'placement' => 'prepend')),                     array('decorator' => array('row' => 'HtmlTag'), 'options' => 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',                 ));                   $this->addElement('submit', 'submit', array(                     'label'      => 'Update Me',                     'decorators' => $button_decorator,                 ));             }         }            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>          
   

没有评论: