QuickForm: add preValidation hook

Allows to modify form properties depending on submitted values before
validating them
This commit is contained in:
Thomas Gelf 2015-06-08 14:38:05 +02:00
parent b4fdb6b64e
commit 88d87b1e5c
2 changed files with 8 additions and 0 deletions

View File

@ -96,6 +96,9 @@ abstract class DirectorObjectForm extends QuickForm
$this->addHidden('id'); $this->addHidden('id');
} }
$this->setDefaults($this->object->getProperties()); $this->setDefaults($this->object->getProperties());
if (! $this->hasBeenSubmitted()) {
$this->beforeValidation($this->object->getProperties());
}
return $this; return $this;
} }

View File

@ -112,6 +112,10 @@ abstract class QuickForm extends Zend_Form
return $this->hasBeenSent(); return $this->hasBeenSent();
} }
protected function beforeValidation($data = array())
{
}
public function handleRequest(Request $request = null) public function handleRequest(Request $request = null)
{ {
if ($request !== null) { if ($request !== null) {
@ -121,6 +125,7 @@ abstract class QuickForm extends Zend_Form
if ($this->hasBeenSent()) { if ($this->hasBeenSent()) {
$post = $this->getRequest()->getPost(); $post = $this->getRequest()->getPost();
if ($this->hasBeenSubmitted()) { if ($this->hasBeenSubmitted()) {
$this->beforeValidation($post);
if ($this->isValid($post)) { if ($this->isValid($post)) {
$this->onSuccess(); $this->onSuccess();
} else { } else {