Mar 19, 2009 10
How can i mark all required form fields with a *?
create file lib/gfFormHerlp.class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?php /** * Some usefull form helper * * @package symfony * @subpackage helper * @author Gordon Franke <gfranke@nevalon.de> * @link http://www.nevalon.de */ class gfFormHelper { /** * Add * to required field labels * * @param sfForm $form * @param string $symbol * @param string $title * * @return void */ public static function addRequiredToLabel(sfForm $form, $symbol = '*', $title = 'This field is mandatory.') { $widgetSchema = $form->getWidgetSchema(); $validatorSchema = $form->getValidatorSchema(); foreach($form->getFormFieldSchema()->getWidget()->getFields() as $key => $object) { $label = $form->getFormFieldSchema()->offsetGet($key)->renderLabelName(); if(isset($validatorSchema[$key]) and $validatorSchema[$key]->getOption('required') == true) { $label .= '<sup title="' . $widgetSchema->getFormFormatter()->translate($title) . '">' . $symbol . '</sup>'; } $widgetSchema->setLabel($key, $label); } } } |
add at the end of your form setup or better when you have subforms into the configure method this line
1 | gfFormHelper::addRequiredToLabel($this); |


Recent Comments