理由はわかりませんが、必要なフィールドがレンダリングされていない symfony フォームがある場合、isValid
関数はそれらをチェックしないことを思い出しました。
つまり、使用時にウィジェットが値を取得したかどうかのみをチェックします。そして、私の現在のプロジェクトではそれが間違っているようです。
これを可能にする設定または何かがありますか?
編集:ここにフォームがあります:
class DemandeForm extends BaseDemandeForm
{
public function configure()
{
$this->widgetSchema['DEMANDE_DESC'] = new sfWidgetFormTextarea();
$this->validatorSchema['DEMANDE_DESC'] = new sfValidatorString(array('required' => true),
array("required" => str_replace('$1','Description de la demande',MessagePeer::getFrameworkMessageFromNum(7))));
$this->validatorSchema['DEMANDE_LIB'] = new sfValidatorString(array('required' => true),
array("required" => str_replace('$1','Libelle de la demande',MessagePeer::getFrameworkMessageFromNum(7))));
$this->widgetSchema['TIERS_ID'] = new crfcWidgetAutocomplete();
$this->validatorSchema['TIERS_ID'] = new sfValidatorString(array('required' => true),
array("required" => str_replace('$1','Tiers',MessagePeer::getFrameworkMessageFromNum(7))));
$bat_choices = $this->getOption('bat_choices');
$this->widgetSchema['BAT_CODE'] = new sfWidgetFormChoice(array('choices' => $bat_choices , 'expanded' => false, 'multiple' => false));
$this->validatorSchema['BAT_CODE'] = new sfValidatorChoice(array('choices' => array_keys($bat_choices),'required' => false)
);
$local_choices = $this->getOption('local_choices');
$this->widgetSchema['LOCAL_CODE'] = new sfWidgetFormChoice(array('choices' => $local_choices, 'expanded' => false, 'multiple' => false));
$this->validatorSchema['LOCAL_CODE'] = new sfValidatorChoice(array('choices' => array_keys($local_choices),'required' => false)
);
$site_choices = $this->getOption('site_choices');
$this->widgetSchema['SITE_CODE'] = new sfWidgetFormChoice(array('choices' => $site_choices, 'expanded' => false, 'multiple' => false));
$this->validatorSchema['SITE_CODE'] = new sfValidatorChoice(array('choices' => array_keys($site_choices),'required' => false)
);
$ress = Array(""=>"") + EnumereValeurPeer::getByType('FONCTIONS',true);
$this->widgetSchema['FONCTION_EVAL_NUMINT'] = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
$this->validatorSchema['FONCTION_EVAL_NUMINT'] = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
array("required" => str_replace('$1','Fonction demandeur',MessagePeer::getFrameworkMessageFromNum(7))));
$ress = Array(""=>"") + EnumereValeurPeer::getByType('CIRCONSTANCE',true);
$this->widgetSchema['CIRCONSTANCE_EVAL_NUMINT'] = new sfWidgetFormChoice(array('choices' => $ress, 'expanded' => false, 'multiple' => false));
$this->validatorSchema['CIRCONSTANCE_EVAL_NUMINT'] = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
array("required" => str_replace('$1','Circonstance de la demande',MessagePeer::getFrameworkMessageFromNum(7))));
$ress = Array(""=>"") + EnumereValeurPeer::getByType('TRAVAUX',true);
$this->widgetSchema['CATEGORIE_EVAL_NUMINT'] = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
$this->validatorSchema['CATEGORIE_EVAL_NUMINT'] = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
array("required" => str_replace('$1','Catégorie de travaux',MessagePeer::getFrameworkMessageFromNum(7)))
);
$ress = Array(""=>"") + EnumereValeurPeer::getByType('QUALIFICATION',true);
$this->widgetSchema['QUALIFICATION_EVAL_NUMINT'] = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
$this->validatorSchema['QUALIFICATION_EVAL_NUMINT'] = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => true),
array("required" => str_replace('$1','Qualification',MessagePeer::getFrameworkMessageFromNum(7)))
);
$ress = Array(""=>"") + EnumereValeurPeer::getByType('PROGRAMME',true);
$this->widgetSchema['PROGRAMME_EVAL_NUMINT'] = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
$this->validatorSchema['PROGRAMME_EVAL_NUMINT'] = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => true),
array("required" => str_replace('$1','Programme',MessagePeer::getFrameworkMessageFromNum(7)))
);
$ress = Array(""=>"") + EnumereValeurPeer::getByType('SUPPORT',true);
$this->widgetSchema['SUPPORT_EVAL_NUMINT'] = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
$this->validatorSchema['SUPPORT_EVAL_NUMINT'] = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
array("required" => str_replace('$1','Support',MessagePeer::getFrameworkMessageFromNum(7))));
$this->widgetSchema['COMMENTAIRE'] = new sfWidgetFormTextarea();
$this->validatorSchema['COMMENTAIRE'] = new sfValidatorString(array('required' => false));
$this->widgetSchema['DEMANDE_DTDEM'] = new myWidgetFormRichDate();
$this->validatorSchema['DEMANDE_DTDEM'] = new sfValidatorDate(array('required' => true, 'date_format'=>'@(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})@'),
array('required'=> str_replace('$1','Date de la demande',MessagePeer::getFrameworkMessageFromNum(7)),
'bad_format' => str_replace('$1','Date de la demande',MessagePeer::getFrameworkMessageFromNum(19)),
'invalid' => str_replace('$1','Date de la demande',MessagePeer::getFrameworkMessageFromNum(19))));
$this->widgetSchema['DEMANDE_DTFIN'] = new myWidgetFormRichDate();
$this->validatorSchema['DEMANDE_DTFIN'] = new sfValidatorDate(array('required' => true, 'date_format'=>'@(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})@'),
array('required'=> str_replace('$1','Date de fin des travax souhaitée',MessagePeer::getFrameworkMessageFromNum(7)),
'bad_format' => str_replace('$1','Date de fin des travax souhaitée',MessagePeer::getFrameworkMessageFromNum(19)),
'invalid' => str_replace('$1','Date de fin des travax souhaitée',MessagePeer::getFrameworkMessageFromNum(19))));
$this->widgetSchema['DEMANDE_ACCESSIBILITE'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['DEMANDE_ACCESSIBILITE'] = new sfValidatorBoolean(array('required' => false));
$this->widgetSchema['DEMANDE_URGENT'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['DEMANDE_URGENT'] = new sfValidatorBoolean(array('required' => false));
$this->widgetSchema['DEMANDE_INCENDIE'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['DEMANDE_INCENDIE'] = new sfValidatorBoolean(array('required' => false));
$this->validatorSchema->setOption('allow_extra_fields' , true);
$this->validatorSchema->setOption('filter_extra_fields' , false);
}
}
編集2:
問題は次のとおりです: DEMANDE_DTDEM フィールドが必須であるよりも正常であり、必須フォーム フィールド エラーが発生しますが、レンダリングされていませんか?
彼が使用されたときだけフォームフィールドを検証すべきではありませんか?