Using HTML objects in a Zend form form

I fill out the Select Form element, and if I try to use HTML objects in a value, it is converted rather than displaying a special character.

This code:

$form->field_name->addMultiOption('value', ' • label');

Renders:

<option value="one">&amp;nbsp;&amp;bull; label</option>

But I want it to be:

<option value="one">&nbsp;&bull; label</option>

How can I use HTML objects here?


prompt

I dug up the code and found that it uses the function escape()from Zend View Abstract on the AND label and value. Maybe someone knows how to override / overload this function for a specific form element? I do not want to override this default behavior.

Function from class Zend_View_Helper_FormSelect

protected function _build($value, $label, $selected, $disable)
{
    if (is_bool($disable)) {
        $disable = array();
    }

    $opt = '<option'
         . ' value="' . $this->view->escape($value) . '"'
         . ' label="' . $this->view->escape($label) . '"';

    // selected?
    if (in_array((string) $value, $selected)) {
        $opt .= ' selected="selected"';
    }

    // disabled?
    if (in_array($value, $disable)) {
        $opt .= ' disabled="disabled"';
    }

    $opt .= '>' . $this->view->escape($label) . "</option>";

    return $opt;
}

This is a class function Zend_View_Abstract:

private $_escape = 'htmlspecialchars';

/* SNIP */

public function escape($var)
{
    if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) {
        return call_user_func($this->_escape, $var, ENT_COMPAT, $this->_encoding);
    }

    return call_user_func($this->_escape, $var);
}
+5
source share
2

, , .

:

$form->field_name->addMultiOption('value', '&nbsp;&bull; label');

:

$form->field_name->addMultiOption('value',
    html_entity_decode('&nbsp;&bull;', ENT_COMPAT, 'UTF-8') . ' label');
+10

/ Zend .

$form->getElement('yourElementName')->clearFilters();
// pupulate the element 

Zend, .

+1

All Articles