开发者

How to append two elements in one div?

I have form and I want to add several elements in one div. But I thing I have made a mistake. Can some one help me. Here is my code:

class Application_Form_Register extends Zend_Form
{
    public function init()
    {
        $this->addElement('text', 'a', array(
            'label' => 'aa',
            'required'  => true,
        ));
        $this->addElement('text', 'b', array(
            'label' => 'bb',
            'required'  => true,
        ));
        $this->addElement('text', 'c', array(
            'label' => 'cc',
            'required'  => true,
        ));
        $this->addElement('text', 'd', array(
            'label' => 'dd',
            'required'  => true,
        ));
        $this->addElement('text', 'e', array(
            'label' => 'ee',
            'required'  => true,
        ));

        $this->getElement('c')->addDecorator('HtmlTag', array('tag' => 'div', 'openOnly' => 'true',  'placement' => Zend_Form_Decorator_Abstract::PREPEND,));
        $this->getElement('d')->addDecorator('HtmlTag', array('tag' => 'div', 'closeOnly' => 'true',));
    }
}

Then i render form i get html like:

<form enctype="application/x-www-form-urlencoded" action="" method="post">
<dl class="zend_form">
<dt id="a-label"><label for="a" class="required">aa</label></dt>

<dd id="a-element">
<input type="text" name="a" id="a" value="" /></dd>
<dt id="b-label"><label for="b" class="required">bb</label></dt>
<dd id="b-element">
<input type="text" name="b" id="b" value="" /></dd>
<dt id="c-label"><label for="c" class="required">cc</lab开发者_JS百科el></dt>

<div>

<input type="text" name="c" id="c" value="" />
<dt id="d-label"><label for="d" class="required">dd</label></dt>

<input type="text" name="d" id="d" value="" />

</div>

<dt id="e-label"><label for="e" class="required">ee</label></dt>

I set decoratos to set DIV to enclose C and D element, but i get enclosed D and C input but not C label

Ho to get DIV up before line:

<dt id="c-label"><label for="c" class="required">cc</label></dt>


Display groups are ment to group form elements. I'd stick with them. Beware of divitis.


for changing your Html output i would try to use some custom form element objects that uses a different view helper. In ehivh you can easily define how the output is supposed to look like, e.g. placement and wrapping of labels and all other subparts of the element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜