Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2008, 12:00 PM
Junior Member
 
Join Date: Jun 2008
Posts: 2
Default Zend_Form + HtmlEntities Filter problem/question

None of the forums were labeled to be used for Zend_Form, and this seemed like the best one, so here goes...

I'm working on a project and using ZF. Slight learning curve, but once you're over that it's pretty powerful. I'm using it for everything I can (database, caching, logging, MVC, etc.)

I'm using Zend_Form to generate a form with elements. Here's an example of an element I'm generating in one particular form

Code:
		$lastname		= $this->addElement( 'text', 'lastname', array(
																	'filters'		=> array( 'StripSlashes', 'StripTags', array( 'HtmlEntities', array(ENT_QUOTES) ) ),
																	'validators'	=> array(
																							array( 'StringLength', false, array( 0, 255 ) ),
																							),
																	'required'		=> true,
																	'allowEmpty'	=> false,
																	'label'			=> 'Last Name:',
										)							);
The same form class is used for adding and editing because, naturally, I need the same fields to be displayed. I simply use $form->setDefaults( array() ) to set the fields appropriately from my database result set.

The problem I'm running into has to do with the htmlentities filter.

Upon submission, StripSlashes removes slashes if gpc is enabled (custom filter), striptags removes HTML tags, and htmlentities converts the appropriate characters to htmlentities. All works just fine.

Then when I pass the data to the form as such

Code:
    	$form				= $this->editContact( $result );
    	$form->setDefaults( array(
    							'firstname'		=> html_entity_decode( $result['contacts_first_name'], ENT_QUOTES ),
    							'lastname'		=> html_entity_decode( $result['contacts_last_name'], ENT_QUOTES ),
.......
  ) );
The data is actually double-html-entity encoded for some reason.

If I var_dump the value I'm passing it is correct (in this test case "o'Doe"), but the actual form field data being generated is like so

Code:
<input type="text" name="lastname" id="lastname" value="o&amp;#039;Doe"></dd>
In case the forum filters it, it's "o& amp;# 039;Doe" with no spaces. I can understand why it's being htmlentity encoded, as that's the filter on the field, but why is it being DOUBLE htmlentity encoded. Does anyone have any ideas here?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:22 AM.