2010年10月25日星期一

Re: [fw-mvc] Forms and HTML

Change your addElement to:

$this -> addElement( 'select', 'types', array(
'label' => '<span style="font: 14pt Frutiger LT Std; color: #00B3FF;"><b>What type of home do you live in:</b></span><br />',
'escape' => false,
'required' => true,
'multiOptions' => array(
'Existing Home' => 'Existing Home',
'New Construction' => 'New Construction',
'Condominium' => 'Condominium',
'Apartment' => 'Apartment'
),
'decorators' => array(
'ViewHelper',
'Errors',
array( 'HtmlTag', array( 'tag' => 'dd' ) ),
array( 'Label', array( 'tag' => 'dt', 'escape' => false) )
)
));

You can optionally leave out the "decorators" key from the options array and instead select the element from the form and manually alter the decorator:

$this -> getElement( 'types' ) -> getDecorator( 'Label' ) -> setOption( 'escape', false );

Ideally, you should be writing a separate label decorator and view
helper simply because you have so much HTML in your label attribute.
Look at the source code for the classes Zend_Form_Decorator_Label and
Zend_View_Helper_FormLabel and extend them so you can get what you need
without having to create an HTML headache with each element in your form.

Logan McGrath


On 10/25/2010 12:00 PM, Thomas List wrote:
> Helllo,
>
> I posted this last week, and I am still having a problem with getting HTML integrated with my form. I am setting the escape value to false, but it still doesn't seem to render the HTML for the label, for example, I have this element in my form:
>
> $this->addElement('select','types', array(
> 'label' => '<span>font: 14pt Frutiger LT Std;color:#00B3FF;><b>What type of home do you live in:</b></span><br/>',
> 'escape' => false,
> 'required' => true,
> 'multiOptions' => array( 'Existing Home' => 'Existing Home', 'New Construction' => 'New Construction', 'Condominium' => 'Condominium', 'Apartment' => 'Apartment',),));
>
> I'm not quite sure what I am missing, but I can't seem to render HTML for the label. Is there something else I need to add to my form class?
>
> Thank You,
> Thomas List
>

没有评论: