Access formdata internally using a public helper method

This way concrete form implementations can also simply fetch form
dependent request values without referring to the form's submission
method.

refs #5525
This commit is contained in:
Johannes Meyer 2014-08-27 10:19:33 +02:00
parent 65dd3f9a5b
commit d3c2fc858c

View File

@ -361,7 +361,7 @@ class Form extends Zend_Form
* *
* @param Request $request The request to be processed * @param Request $request The request to be processed
* *
* @return self * @return Request The request supposed to be processed
*/ */
public function handleRequest(Request $request = null) public function handleRequest(Request $request = null)
{ {
@ -369,26 +369,24 @@ class Form extends Zend_Form
$request = $this->getRequest(); $request = $this->getRequest();
} }
if (strtolower($request->getMethod()) === $this->getMethod()) { $formData = $this->getRequestData($request);
$formData = $request->{'get' . $request->isPost() ? 'Post' : 'Query'}(); if ($this->wasSent($formData)) {
if ($this->wasSent($formData)) { $this->populate($formData); // Necessary to get isSubmitted() to work
$this->populate($formData); // Necessary to get isSubmitted() to work if ($this->isSubmitted()) {
if ($this->isSubmitted()) { if ($this->isValid($formData)) {
if ($this->isValid($formData)) { if ($this->onSuccess($request)) {
if ($this->onSuccess($request)) { $this->getResponse()->redirectAndExit($this->getRedirectUrl());
$this->getResponse()->redirectAndExit($this->getRedirectUrl());
}
} else {
$this->onFailure($request);
} }
} else { } else {
// The form can't be processed but we want to show validation errors though $this->onFailure($request);
$this->isValidPartial($formData);
} }
} else {
// The form can't be processed but we want to show validation errors though
$this->isValidPartial($formData);
} }
} }
return $this; return $request;
} }
/** /**
@ -509,6 +507,22 @@ class Form extends Zend_Form
return $name; return $name;
} }
/**
* Return the request data based on this form's request method
*
* @param Request $request The request to fetch the data from
*
* @return array
*/
public function getRequestData(Request $request)
{
if (strtolower($request->getMethod()) === $this->getMethod()) {
return $request->{'get' . ($request->isPost() ? 'Post' : 'Query')}();
}
return array();
}
/** /**
* Return the current request * Return the current request
* *