A typical Developer Blog
by Gordon Franke
Icon

Wie kann man in symfony 1.3 einfach alle Formular Pflichtfelder kennzeichnen?

Erstelle eine Funktion in deiner BaseForm Klasse

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'));

Related posts:

  1. Wie kann ich alle Formular Pflichtfelder mit einem * kennzeichnen? Erstelle die Datei lib/gfFormHerlp.class.php 1 2 3 4 5 6...
  2. Wie kann ich eingebettete Formulare oder einzelne Felder abhängig von einem Formularfeld verwenden? Du hast ein Registrierungsformular mit einem Feld account_type und zwei...
  3. Wie kann ich ein symfony event aus dem doctrine model herraus aufrufen? 1 2 $dispatcher = sfProjectConfiguration::getActive()->getEventDispatcher(); $dispatcher->notify($event); ...

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

Author: Gordon Franke

Category: Uncategorized, symfony

Tagged: , ,

Leave a Reply

CommentLuv Enabled