Dondariadmin (トーク | 投稿記録) (ページの作成:「== sfFormの複数項目バリデータ == * sfFormのバリデータ指定はフィールド単体に対するものが基本となっています。 * では、“検...」) |
Dondariadmin (トーク | 投稿記録) (→PostValidator内に複数のバリデータを設定するには) |
||
25行目: | 25行目: | ||
} | } | ||
− | == | + | == postValidator内に複数のバリデータを設定するには == |
* 上記で複数項目のチェックはできました。では、上記に加えて、勤続年数範囲条件も追加する場合。 | * 上記で複数項目のチェックはできました。では、上記に加えて、勤続年数範囲条件も追加する場合。 |
class hogeForm extends BaseForm { public function configure() { $this->setWidgets(array( 'age_from' => new sfWidgetFormInputText(), 'age_to' => new sfWidgetFormInputText(), )); $this->getValidatorSchema()->setPostValidator( // '<='等の比較演算子文字列は、sfValidatorSchemaCompareクラス内に定数宣言もありますが、このほうが分かりやすいように思います。 new sfValidatorSchemaCompare('age_from', '<=', 'age_to') ); $this->getWidgetSchema()->setNameFormat('hogeinput[%s]'); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); } }
class hogeForm extends BaseForm { public function configure() { $this->setWidgets(array( 'age_from' => new sfWidgetFormInputText(), 'age_to' => new sfWidgetFormInputText(), 'work_length_from' => new sfWidgetFormInputText(), 'work_length_to' => new sfWidgetFormInputText(), )); $this->setValidators(array( 'age_from' => new sfValidatorInteger(), 'age_to' => new sfValidatorInteger(), 'work_length_from' => new sfValidatorInteger(), 'work_length_to' => new sfValidatorInteger(), )); $this->getValidatorSchema()->setPostValidator(new sfValidatorAnd(array( new sfValidatorSchemaCompare('age_from', '<=', 'age_to'), new sfValidatorSchemaCompare('work_length_from', '<=', 'work_length_to'), ))); $this->getWidgetSchema()->setNameFormat('hogeinput[%s]'); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); } }Tweet