Friday, July 26, 2013

Escaping Zend_Form Error Element Labels in ZF1

You have a form element label with extra characters (e.g. *, ", :, etc...) and you want to escape or remove it in the generated error message.

Example Zend Form Element:

$firstName = new Zend_Form_Element_Text('first_name');
$firstName->class = "size_long";
$firstName->setLabel('* First Name:')
          ->ddFilters(array('StringTrim', 'StripTags'))
                array('ViewHelper', array('helper' => 'formText')),
                array('Label', array('class' => 'label')),
                array('HtmlTag', array('tag' => 'div', 'class' => 'el_wrapper')),

Notice the setLabel() method string have characters "*" and ":"
These characters will show up in your error UL labels that are generated by Zend_Form_Decorator_FormErrors.

In your controller when an error is generated...

// assume $form is an instance of Zend_Form
if (!$form->isValid($_POST)) {
    $view = $form->getView();
    $escape = function ($string) use ($view) {
        $string = htmlspecialchars($string, ENT_COMPAT, $view->getEncoding());
        $string = str_replace(array('#', ':', '*'), '', $string);
        return trim($string);

This will override the default "htmlspecialchars" escaping of Zend_Form that is being used in the rendering of form elements.


Unknown said...

Sergei , October 22, 1970 Born in Christian Louboutin Bois Dore Moscow State Ozherelye. Perhaps influenced by Cheap LV Handbags their parents worship warrior army, join the army in cheap jordans 1989, and into the elite airborne military service. 1991, by the influence of the Soviet Union, the uggs on sale Russian christian louboutin army general lack of funds, a large number ugg australia of Air Jordan 11 Gamma Blue soldiers seeking veterans, but under extremely difficult conditions still dedicated, praise superiors, and soon was sent to the famous christian louboutin shoes Ryazan Higher ugg Airborne Command School studies. After graduating in 1994, entered the famous Pskov 76th Guards Airborne discount christian louboutin Division, served as discount nike jordans the reconnaissance platoon, reconnaissance ugg soldes deputy company commander, company commander, battalion airborne regiment scouting director and other duties.From 2000 to Cheap Louis Vuitton Handbags 2004, where the forces have repeatedly ordered war with Chechen militants. Because of their opponents in order to form the squad activity and haunted impermanence, the Russians had to ugg boots mobilize elite troops set up large uggs outlet number of small units, "a Discount Louis Vuitton small wholesale jordan shoes play small" Implementation siege. commanding troops in Chechnya, Christian Louboutin Daffodile Ingushetia and other places over the mountains, to track the militants fled. Discount LV Handbags Although the militants were extremely vigilant, but as long as the task has never had outsmarted.August 8, 2008, Georgia suddenly invade South Ossetia (Russian peacekeepers stationed ugg pas cher there), the Russian military to respond quickly, including including the 76th Guards Airborne Division, more than christian louboutin remise 50% 3,000 people were immediately delivered to the pro-Russian Abkhazia, Georgia cheap nike jordan shoes Army contain two infantry brigades, effectively coordinate the cheap christian louboutin direction of the Russian Bags Louis Vuitton troops in South Ossetia.

Unknown said...

soccer jerseys for sale
abercrombie & fitch
kate spade handbags
air jordan uk
longchamp outlet online
pandora charms
rolex watches for sale
coach outlet store online
coach outlet
true religion jeans outlet
pandora bracelets
oakley sunglasses wholesale
ralph lauren polo shirts
kate spade bags
coach outlet
snapbacks hats
toms shoes for women
soccer shoes for sale
ray bans
beats headphones
hollister kids
gucci handbags
cheap oakley sunglasses
replica watches for sale
coach factory outlet
gucci borse
gucci belt
cheap snabacks
hollister outlet
tory burch outlet
kate spade bags
michael kors
air max 2015
longchamp pliage pas cher
mcm outlet online

Unknown said...

ray ban sunglasses,
nike trainers,
gucci handbags,
herve leger,
timberland boots,
coach outlet online,
michael kors outlet,
juicy couture outlet,
calvin klein underwear,
ray ban sunglasses,
prada outlet,
lululemon outlet,
tory burch shoes,
michael kors outlet,
replica watches,
pandora jewelry,
nfl jerseys wholesale,
michael kors outlet,
oakley outlet,
oakley sunglasses,
michael kors bags,
ray ban sunglasses,
oakley sunglasses,
air max 2015,
the north face uk,
swarovski outlet,
pandora jewelry,
chanel handbags,

oakleyses said...

moncler, moncler outlet, marc jacobs, moncler, hollister, montre pas cher, vans, ray ban, replica watches, pandora charms, louis vuitton, supra shoes, sac louis vuitton pas cher, pandora jewelry, swarovski, pandora charms, moncler, bottes ugg, barbour, canada goose, ugg,uggs,uggs canada, louis vuitton, doke gabbana outlet, converse, louis vuitton, lancel, louis vuitton, hollister, moncler, pandora jewelry, doudoune canada goose, juicy couture outlet, nike air max, converse outlet, barbour jackets, moncler, ugg,ugg australia,ugg italia, links of london, moncler, gucci, canada goose outlet, canada goose, canada goose outlet, coach outlet, canada goose uk, ugg boots uk, canada goose, juicy couture outlet, ugg pas cher, wedding dresses, canada goose

Unknown said...

thomas sabo uk
herve leger outlet
coach outlet online
louis vuitton handbags
rolex watches
ugg boots
iphone case
cheap snapbacks
uggs outlet
michael kors outlet online
cartier outlet
michael kors outlet clearance
soccer jerseys
oakley sunglasses
celine outlet
canada goose outlet
coach outlet
futbol baratas
nike air force 1
longchamp outlet
coach outlet
michael kors outlet
ugg outlet
canada goose jackets
hermes birkin
polo ralph lauren
michael kors outlet store
air jordan 4
cheap uggs
tory burch outlet
tiffany and co jewelry
louis vuitton outlet
coach outlet
michael kors bags
ugg boots

Unknown said...

michael kors handbags clearance
nike free
ghd hair straighteners
michael kors handbags wholesale
true religion jeans
nike trainers
ed hardy outlet
san antonio spurs
salvatore ferragamo
michael kors handbags sale

Digital Marketing Agency said...

Quikcbooks Support Phone Number

[url=]Quikcbooks Support Number[/url]
[url=]Quikcbooks Support Phone Number[/url]
[url=]Quikcbooks Tech Support Number[/url]
[url=]Quikcbooks Technical Support Number[/url]
[url=]Quikcbooks Tech Support Phone Number[/url]
[url=]Quikcbooks Helpdesk Phone Numbe[/url]
[url=]Quikcbooks Technical Support Phone Number[/url]
[url=]Quikcbooks Customer Service Phone Number[/url]
[url=]Quikcbooks Customer Support Number[/url]

Quicken Support Phone Number

Quicken Support Number
Quicken Support Phone Number
Quicken Tech Support Number
Quicken Technical Support Number
Quicken Tech Support Phone Number
Quicken Technical Support Phone Number
Quicken Helpdesk Phone Number
Quicken Customer Service Phone Number
Quicken Customer Service Number
Quicken Customer Support Number

Sage Support Phone Number

Sage Support Number
Sage Support Phone Number
SageTech Support Number
Sage Technical Support Number
Sage Tech Support Phone Number
Sage Technical Support Phone Number
Sage Helpdesk Phone Number
Sage Customer Service Phone Number
Sage Customer Service Number
Sage Customer Support Number