
|
Zend_Form html entities problem
Hi everyone,
quick question; I am trying to create a dropdown box with all the country codes and names. The problem is, however, that many of these countries need html entities (as they contain umlauts, accent graves etcetera). If I use html entities like ë it will be converted by zend_form to ¨
Does anyone know how to circumvent this?
Sample code:
$this->addElement('select', 'country', array( 'validators' => array(
array( 'regex', false, array('/^[A-Z]{2}$/', ), ),
'label'=>'Land:', 'required' => true, 'multiOptions' => array( 'AF'=>'Afghanistan','AL'=>'Albanië','DZ'=>'Algerije','AS'=>'Amerikaanse Samoa','AD'=>'Andorra','AO'=>'Angola','AI'=>'Anguilla',
), 'decorators' => $this->elementDecorators ));
Thanks for helping!
Regards, Pieter
|

|
Re: Zend_Form html entities problem
Thanks Adam! Your solution works great. On Mon, Sep 8, 2008 at 3:14 PM, Adam Hunter <ah125i@...> wrote:
Hi,
This is because Zend_Form render's through Zend_View's helpers. This escapes form values by default. I use (in my controller) $this->view->setEscape('stripslashes'). This way your form values won't be converted to HTML Entities. From inside your form class you can do $this->getView()->setEscape('stripslashes').
Hope this helps.
AdamOn Mon, Sep 8, 2008 at 8:36 AM, Pieter <ptrwrsm@...> wrote:
Hi everyone,
quick question; I am trying to create a dropdown box with all the country codes and names. The problem is, however, that many of these countries need html entities (as they contain umlauts, accent graves etcetera). If I use html entities like ë it will be converted by zend_form to &uml;
Does anyone know how to circumvent this?
Sample code:
$this->addElement('select', 'country', array( 'validators' => array(
array( 'regex', false, array('/^[A-Z]{2}$/', ), ),
'label'=>'Land:', 'required' => true, 'multiOptions' => array( 'AF'=>'Afghanistan','AL'=>'Albanië','DZ'=>'Algerije','AS'=>'Amerikaanse Samoa','AD'=>'Andorra','AO'=>'Angola','AI'=>'Anguilla',
), 'decorators' => $this->elementDecorators ));
Thanks for helping!
Regards, Pieter
|

|
Re: Zend_Form html entities problem
Thanks Jason. Good to know it's that easy to overwrite those functions. On Mon, Sep 8, 2008 at 3:19 PM, Jason Stames <jstames@...> wrote:
You can override the view escape function. All view helpers inherit their escape function from the view.
//Anywhere this will be seen by the Zend Engine before used below
//This is a dummy escape function
function noEscape($value)
{
return $value;
}
//Place somewhere in your controller - after the view is initialized
//Set the view escape function
$this->view->setEscape('noEscape');
You can also override the default escape function for your specific select object if you still want the view to escape other output...
//Anywhere this will be seen by the Zend Engine before used below
//This is a dummy escape function
function noEscape($value)
{
return $value;
}
//In your controller
$select->setEscape('noEscape');
If you cross a better method, please let me know.
- Jason
On 2008-09-08, at 05:36:56, Pieter wrote:
Hi everyone,
quick question; I am trying to create a dropdown box with all the country codes and names. The problem is, however, that many of these countries need html entities (as they contain umlauts, accent graves etcetera). If I use html entities like ë it will be converted by zend_form to &uml;
Does anyone know how to circumvent this?
Sample code:
$this->addElement('select', 'country', array(
'validators' => array(
array(
'regex', false, array('/^[A-Z]{2}$/',
),
),
'label'=>'Land:',
'required' => true,
'multiOptions' => array(
'AF'=>'Afghanistan','AL'=>'Albanië','DZ'=>'Algerije','AS'=>'Amerikaanse Samoa','AD'=>'Andorra','AO'=>'Angola','AI'=>'Anguilla',
),
'decorators' => $this->elementDecorators
));
Thanks for helping!
Regards,
Pieter
|

|
Re: Zend_Form html entities problem
I'm having the same problems with simply displaying html with a simple echo function. The view escape is converting all the html entities in my data to ascii. I tried turning it off using this noEscape function but I must be missing something. The escape callback is not working and needs to be a valid one as defined in Abstract.php in library/Zend/View. Do I only have two default choices 'htmlspecialchars' and 'htmlspecialentities'??
|