U
U
usja2011-05-19 10:24:19
Zend Framework
usja, 2011-05-19 10:24:19

Zend Form and adding custom divs to the form

Zend_Form creates a form.
It can be displayed in a view in one line
<?php echo $this->myform;?>
. But a situation arose when, in addition to standard elements, several divs must be inserted into the form.
How can you correctly add any html elements to the form?
There is an option to display in the view element by element using renderViewHelper () and insert your own div in the right place, but in my opinion this is not good.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zizop, 2011-05-19
@usja

I myself somehow faced a similar problem. As a result, wrote Zend_Form_Decorator_HtmlTag. Here is an article from that time: Arbitrary html code in Zend_Form

P
patashnik, 2011-05-19
@patashnik

What will be inside the div? Have you tried using decorators on elements?

O
OldFornit, 2011-05-19
@OldFornit

function loadDefaultDecorators() {
parent::loadDefaultDecorators();
$this->setElementDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'p')),
array('Label', array('tag' => 'p')),
array(array('row' => 'HtmlTag'), array('tag' => 'div'))
));
foreach ($this->getElements() as $element) {
if ('Zend_Form_Element_Submit' == $element->getType()) {
$element->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('row' =>
'HtmlTag'), array('tag' => 'div')) ));
}
if ('Zend_Form_Element_Hidden' == $element->getType()) {
$element->setDecorators(array(
'ViewHelper',
));
}
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question