A typical Developer Blog
by Gordon Franke
Icon

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 eingebetteten Formularen Company und Address.

Du willst das eingebettete Company Formular entfernen, wenn das Feld account_type sfGuardUserProfile::TYPE_PRIVATE entspricht, andernfalls willst du das eingebettete Address Formular entfernen.

Die Lösung ist die bind Methode in deinem Formular zu überschreiben.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  public function bind(array $taintedValues = null, array $taintedFiles = null)
  {
    // unset request param and validator
    if($taintedValues['account_type'] == sfGuardUserProfile::TYPE_PRIVATE)
    {
      unset(
        $taintedValues['Company'],
        $this->validatorSchema['Company']
      );
    }
    else
    {
      unset(
        $taintedValues['Address'],
        $this->validatorSchema['Address']
      );
    }
 
    parent::bind($taintedValues, $taintedFiles);
  }

No related posts.

Ähnliche Artikel bereitgestellt von Yet Another Related Posts Plugin.

Author:

Category: doctrine, symfony, Uncategorized

Tagged: , , , ,

Leave a Reply

CommentLuv badge