سؤال

I am trying to add some html to a zend form but I can't find what I want. So I create the elements then I have this code:

$form->addDisplayGroup(array('firstElement', 'secondElement'), 'user', array('legend' => 'My legend'));

$form->setDisplayGroupDecorators(array(
    'FormElements',
    array('HtmlTag', array('class'=>'myClass', 'tag' => 'div'))
));

I get rid of the fieldset and the legend because it's impossible to style it correctly. So I replace the fieldset with a div, but I need to create a h2 or something to replace the legend. Is there any way to add this in the group decorators?

PS: I know there is a lot of similar questions and I tried them all. It didn't work mainly because I can't add a form element in Zend Framework (I don't have access to the directory to add a class on the server).

هل كانت مفيدة؟

المحلول

I finally found the solution to my problem with the description. In case anybody has the same issue, here is how I did:

$group = $form->getDisplayGroup('nameOfTheGroup');
$group->setDescription('The text you want');
$group->setDecorators(array(
    'FormElements',
    array('HtmlTag', array('tag' => 'div', 'class' => 'myClass')),
    array('Description', array('tag' => 'h2', 'placement' => 'prepend'))
));

This will add the description in a h2 tag before the div.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top