0
votes

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).

1
I get rid of the fieldset and the legend because it's impossible to style it correctly Well, that depends on what you understand under 'correctly'. It is very well possible to style fieldset and legend with CSSDirk McQuickly
Yes it was a bit stupid to say that this way (I have to admit I was a bit angry because of my problem). What I meant is that I find it really hard to make something 100% cross browser. But it's specific to the design I had to realize and because I had to make it exactly similar from modern browser to IE7.romainberger

1 Answers

3
votes

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.