Search code examples
zend-frameworkzend-formzend-decorators

Zend_Form : Use images instead of text labels?


I'd like to replace the common input's labels with some images. I have a multicheckbox with a country list, and I want to display for each checkbox the country flag instead of it's name.

I tried to put an <img/> tag as label value, but this html is escaped and displayed as text instead of displaying the images...

Is there a native solution ? Should I create a custom decorator ?

I'm currently trying to create a custom decorator but I'm noob and I'm pretty sure there is an other cleaner way for this ! Thanks for help...


Solution

  • Ok I finally found by myself... It was so simple that I didn't even think about it.

    When you create a form element, it's possible to set the option escape to false :

    $this->addElement('multiCheckbox', 'countries', array(
        'filters'    => array(/* some filters */),
        'validators' => array(/* some validators */),
        'label'      => 'Countries :',
        'decorators'  => array( /* some decorators */ ),
        'escape'     => false, /* will prevent the checkboxes' labels to be escaped */
    ));
    

    As my checkboxes' labels aren't escaped anymore, I can set some html inside :)