UI\Form ignores forwarded requests
- urug
- Member | 4
The problem lies in:
Nette\Application\UI\Form::receiveHttpData()
<?php
//...
if ($request->isMethod('forward') || $request->isMethod('post') !== $isPost) {
return;
}
//...
?>
Why are the recieved data ignored and the form is considered unsubmitted when
forwarded request is being processed?
I think that forward should hand over the processing to antoher
presenter/action and continue as usual, why there should be some side
effects?
Are there any other differences in processing forwarded request I should
know about?
Currently I am trying to forward the current request to different presenter, while keeping all the associated data, like this:
<?php
class ForwardingPresenter extends BasePresenter {
public function startup() {
parent::startup();
$appRequest = $this->getRequest(); // get current request
$appRequest->setPresenterName("PresenterNameIsDeterminedDynamically"); // change presenter
$appRequest->setMethod(\Nette\Application\Request::FORWARD); // if this is not done, the forward() actually causes redirect with 301 code (also kinda weird behaviour)
return $this->forward($appRequest);
}
}
?>
Last edited by urug (2015-11-27 14:59)
- enumag
- Member | 2118
Forward is fine like this in my opinion. The weird behaviour is your ForwardingPresenter. You should use router to determine which presenter is supposed to handle the request.
The “weird” redirect is probably caused by canonicalization and can be disabled.
- urug
- Member | 4
You were right about the canonicalization, I disabled it on forwarded presenter and redirects are gone. So it wasn't the forward method itself causing these redirects, which makes more sense now.
I also removed the
$appRequest->setMethod(\Nette\Application\Request::FORWARD);
which was used only as a workaround for these redirects and it seems that
everything is now working as expected, forms are being properly submitted.
So the conclusion: Forms do not ignore forwarded request as originally stated, unless the forwarded request does have a method FORWARD.
Last edited by urug (2015-11-28 14:59)