Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing HTML Entities in a Zend Form Select
    text
    copied!<p>I am populating a Select form element, and if I try to use HTML Entities in the value, it get's converted, rather than displaying the special character.</p> <p>This code:</p> <pre><code>$form-&gt;field_name-&gt;addMultiOption('value', '&amp;nbsp;&amp;bull; label'); </code></pre> <p>Renders:</p> <pre><code>&lt;option value="one"&gt;&amp;amp;nbsp;&amp;amp;bull; label&lt;/option&gt; </code></pre> <p>But I want it to be:</p> <pre><code>&lt;option value="one"&gt;&amp;nbsp;&amp;bull; label&lt;/option&gt; </code></pre> <p>How do I use HTML entities here?</p> <hr> <p><strong>Hint?</strong></p> <p>I dug in the code and found that it's using the <code>escape()</code> function from the Zend View Abstract on the label <em>AND</em> the value. Maybe someone knows how to override/overload this function for a specific form element? I don't want to override that behavior by default.</p> <p>Function from the <code>Zend_View_Helper_FormSelect</code> class</p> <pre><code>protected function _build($value, $label, $selected, $disable) { if (is_bool($disable)) { $disable = array(); } $opt = '&lt;option' . ' value="' . $this-&gt;view-&gt;escape($value) . '"' . ' label="' . $this-&gt;view-&gt;escape($label) . '"'; // selected? if (in_array((string) $value, $selected)) { $opt .= ' selected="selected"'; } // disabled? if (in_array($value, $disable)) { $opt .= ' disabled="disabled"'; } $opt .= '&gt;' . $this-&gt;view-&gt;escape($label) . "&lt;/option&gt;"; return $opt; } </code></pre> <p>This is the function from the <code>Zend_View_Abstract</code> class:</p> <pre><code>private $_escape = 'htmlspecialchars'; /* SNIP */ public function escape($var) { if (in_array($this-&gt;_escape, array('htmlspecialchars', 'htmlentities'))) { return call_user_func($this-&gt;_escape, $var, ENT_COMPAT, $this-&gt;_encoding); } return call_user_func($this-&gt;_escape, $var); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload