Zend Framework decorator subform add a class tag to DD wrapper tag

Posted by Samuele on Stack Overflow See other posts from Stack Overflow or by Samuele
Published on 2011-11-16T09:49:20Z Indexed on 2011/11/16 9:50 UTC
Read the original article Hit count: 232

Filed under:
|
|
|
|

I have this form:

class Request_Form_Prova extends Zend_Form
{

    public function init()
    {
        $this->setMethod('post');

        $SubForm_Step = new Zend_Form_SubForm();
        $SubForm_Step->setAttrib('class','Step');
        $this->addSubform($SubForm_Step, 'Chicco'); 

        $PrivacyCheck = $SubForm_Step->createElement('CheckBox', 'PrivacyCheck');
        $PrivacyCheck->setLabel('I have read and I agre bla bla...')
                     ->setRequired(true)
                     ->setUncheckedValue('');
        $PrivacyCheck->getDecorator('Label')->setOption('class', 'inline');

        $SubForm_Step->addElement($PrivacyCheck);


        $SubForm_Step->addElement('submit', 'submit', array(
            'ignore'   => true,
            'label'    => 'OK',
        ));
    }
}

That generate this HTML:

<form enctype="application/x-www-form-urlencoded" method="post" action="">
    <dl class="zend_form">
        <dt id="Chicco-label">&nbsp;</dt>
        <dd id="Chicco-element">
            <fieldset id="fieldset-Chicco" class="Step">
                <dl>
                    <dt id="Chicco-PrivacyCheck-label"><label for="Chicco-PrivacyCheck" class="inline required">I have read and I agre bla bla...</label></dt>
                    <dd id="Chicco-PrivacyCheck-element">
                        <input type="hidden" name="Chicco[PrivacyCheck]" value=""><input type="checkbox" name="Chicco[PrivacyCheck]" id="Chicco-PrivacyCheck" value="1">
                    </dd>
                    <dt id="submit-label">&nbsp;</dt>
                    <dd id="submit-element">
                        <input type="submit" name="Chicco[submit]" id="Chicco-submit" value="OK">
                    </dd>
                </dl>
            </fieldset>
        </dd>
    </dl>
</form>

How can I add a class="Test" to the <dd id="Chicco-element"> elemnt? In order to have it like that: <dd id="Chicco-element" class="Test">

I thought something like that but it don't work:

$SubForm_Step->getDecorator('DdWrapper')->setOption('class', 'Test');
OR
$SubForm_Step->getDecorator('DtDdWrapper')->setOption('class', 'Test');

How can I do it?

And last question:

How can I wrap that DD and DT element of a SubForm in another DL element?

Like that: ( second line )

<dl class="zend_form">
  <dl>
     <dt id="Chicco-label">&nbsp;</dt>
     <dd id="Chicco-element">
         <fieldset id="fieldset-Chicco" class="Step">
             <dl>
             .......

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about decorator