From 88d87b1e5c423b343715d1bf8864117067fe3688 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 8 Jun 2015 14:38:05 +0200 Subject: [PATCH] QuickForm: add preValidation hook Allows to modify form properties depending on submitted values before validating them --- library/Director/Web/Form/DirectorObjectForm.php | 3 +++ library/Director/Web/Form/QuickForm.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 3d7bf976..d5949d69 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -96,6 +96,9 @@ abstract class DirectorObjectForm extends QuickForm $this->addHidden('id'); } $this->setDefaults($this->object->getProperties()); + if (! $this->hasBeenSubmitted()) { + $this->beforeValidation($this->object->getProperties()); + } return $this; } diff --git a/library/Director/Web/Form/QuickForm.php b/library/Director/Web/Form/QuickForm.php index 1e92fc73..5069dca3 100644 --- a/library/Director/Web/Form/QuickForm.php +++ b/library/Director/Web/Form/QuickForm.php @@ -112,6 +112,10 @@ abstract class QuickForm extends Zend_Form return $this->hasBeenSent(); } + protected function beforeValidation($data = array()) + { + } + public function handleRequest(Request $request = null) { if ($request !== null) { @@ -121,6 +125,7 @@ abstract class QuickForm extends Zend_Form if ($this->hasBeenSent()) { $post = $this->getRequest()->getPost(); if ($this->hasBeenSubmitted()) { + $this->beforeValidation($post); if ($this->isValid($post)) { $this->onSuccess(); } else {