Decorators in Zend Framework form

334 views Asked by At

i have this little problem, so i'm using zend decorators to put my inputs in table but i need to put 2 text input in the same tr and i have more than 2.

the code i'm using

$title = new Zend_Form_Element_Text('title');
    $title->setAttrib('size', '100');
    $title->setLabel('Title')
            ->setAttrib('class', 'promoinputs');
$begindate = new Zend_Form_Element_Text('begindate');
    $begindate->setLabel('Time')
            ->setAttrib('class', 'dateinputs');

    $enddate = new Zend_Form_Element_Text('enddate');
    $enddate->setLabel('to')
            ->setAttrib('class', 'dateinputs');
    $radius = new Zend_Form_Element_Text('radius');
    $radius->setLabel('Raduis')
            ->setAttrib('class', 'promoinputs');
    $submit = new Zend_Form_Element_Submit('save');

    $this->addElements(array($title, $begindate, $enddate, $radius, $submit));

    $this->setElementDecorators(
            array(
                'ViewHelper',
                array('Errors', array('data' => 'tr')),
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array('Label',  array('tag' => 'td', 'class' => 'promolabel')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'promotr')),
    ));
    $submit->setDecorators(
            array(
                'ViewHelper',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element', 'placement' => 'PREPEND')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));
    $this->setDecorators(
                array(
                    'FormElements',
                    array('HtmlTag', array('tag' => 'table', 'class' => 'promotable')),
                    'Form'
        ));

So i need to put begindate and enddate in the same tr, how can i do it?

1

There are 1 answers

0
Mr Coder On

Use subform for it

   $subform = new Zend_Form_SubForm();
    $subform->addElement($text1)
            ->addElement($text2)
            ->setDecorators('FormElements',array('HtmlTag',array('tag'=>'tr')));

    $form->addSubForm($subform,'my');