Dondariadmin (トーク | 投稿記録) (ページの作成:「== sfFormの複数項目バリデータ == * sfFormのバリデータ指定はフィールド単体に対するものが基本となっています。 * では、“検...」) |
(相違点なし)
|
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