-- J DeBord <[email protected]> wrote
(on Monday, 13 April 2009, 08:39 PM +0200):
> I apoligize in advance for posting another question about these decorators, 
> but
> I just keep banging my head against the wall.
> 
> Please see the html output of this form below.
> 
> class Forms_SubscribeForm extends Zend_Form {
>    
>     public function __construct() {
>        
>         parent::__construct();
>        
>         $this->setAttrib('id','newsletterSubscribe');
>        
>         $email = new Zend_Form_Element_Text('n_email');
>         $email->removeDecorator('DtDdWrapper');
>        
>         $submit = new Zend_Form_Element_Submit('submit');
>         $submit->removeDecorator('DtDdWrapper');
>        
>         $this->addElements(array($email, $submit));
>        
>         $this->clearDecorators();
>         $this->setDecorators(array(
>             'FormElements',
>             array('HtmlTag', array('tag' => '<fieldset>')),
>             'Form'
>         ));
>        
>     }
>    
> }
> 
> HTML:
> 
> 
> <form id="newsletterSubscribe" enctype="application/x-www-form-urlencoded" 
> action="" method="post" name=""><fieldset>
> 
> <dt>&nbsp;</dt>
> <dd>
> <input type="text" name="n_email" id="n_email" value="" /></dd>
> 
> 
> <input type="submit" name="submit" id="submit" value="submit" 
> /></fieldset></form>
> 
> 
> END HTML
> 
> You can see that I was able to get rid of the dd from the submit
> input, but it remains on the text input. I want to completely get rid
> of the definition list and leave only the form tag, fieldset, and
> input tags.
> 
> 
> What am I doing wrong?

Several things. First, you're making some incorrect assumptions about
where the <dt> and <dd> tags are coming from. For most form elements,
the <dd> is added via an HtmlTag decorator, and the <dt> is added via
the Label decorator. Second, you should be overriding the init() method,
not the __construct() method; it's safer. Third, Use the 'Fieldset'
decorator for fieldsets. Finally, use addElement() to create elements,
as it acts as a factory.

Below is a class that accomplishes the goals you have for your HTML
markup:

    class Forms_SubscribeForm extends Zend_Form 
    {
        protected $_defaultDecorators = array(
            'ViewHelper',
        );

        public function init() 
        {
            $this->setAttrib('id', 'newsletterSubscribe');

            $this->addElement('text', 'n_email', array(
                'decorators' => $this->_defaultDecorators,
            ));

            $this->addElement('submit', 'submit', array(
                'decorators' => $this->_defaultDecorators,
            ));

            $this->setDecorators(array(
                'FormElements',
                'Fieldset',
                'Form'
            ));
        }
    }

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to