Quantcast
Viewing all articles
Browse latest Browse all 10

How can i simple mark all required form fields in symfony 1.3?

Create a function in your BaseForm class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static function listenToPostConfigure($event)
{
  $form            = $event->getSubject();
  $widgetSchema    = $form->getWidgetSchema();
  $validatorSchema = $form->getValidatorSchema();
 
  $fields = $form->getFormFieldSchema()->getWidget()->getFields();
  foreach ($fields as $key => $object)
  {
    $label = $form->getFormFieldSchema()->offsetGet($key)->renderLabelName();
    if (isset($validatorSchema[$key]) and $validatorSchema[$key]->getOption('required') == true)
    {
      $title  = $key . '_field_is_required';
      $label .= '<sup>getFormFormatter()->translate($title) . '">*</sup>';
    }
    $widgetSchema->setLabel($key, $label);
  }
}

Add a listener to the form.post_configure event with your function

1
2
$dispatcher = $this->getEventDispatcher();
$dispatcher->connect('form.post_configure', array('BaseForm', 'listenToPostConfigure'));

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Image may be NSFW.
Clik here to view.
flattr this!


Viewing all articles
Browse latest Browse all 10

Trending Articles