How do I tell my TYPO3 Form to add a finisher that redirects to a certain URL? I can see the redirect option. But it always gives me an error message because it need a "number". Which don't even get the point of.
Redirect TYPO3 Form to external URL
208 Views Asked by imconfused At
2
There are 2 best solutions below
0
On
I think there is no standard way in the TYPO3 backend. We wrote a Form Finisher to do the job. But in our case the external URL is called by a request from the server and the response in given back to the initial request. That way it isn't a redirect. We took the core Redirect Finisher as an example.
The actual code is quite simple (endpointUrl is a parameter defined for the finisher). //get the form values $formValues = this->finisherContext->getFormValues(); // get the url parameter from the form settings $endpoint = $this->parseOption('endpointURL');
// cancel all the other finishers because we are the last one
$this->finisherContext->cancel();
// get the post values
$additionalParams =[
'form_params'=> $formValues
];
// send the post values to the external URL as POST parameters
$subResponse = $this->requestFactory->request($endpoint, "POST", $additionalParams);
// transfer the response of the request to the response we will throw in a minute; (maybe we could do without that?)
$response = this->responseFactory->createResponse(200)
->withHeader('content-type', $subResponse->getHeader('content-type'))
->withHeader('Nobit-ExtendedForms', "Redirected from TYPO3 form.")
->withBody($subResponse->getBody());
// throw an exception to get the response out, we didn't come up with a way to get that out the normal redirect-handler-way
throw new PropagateResponseException($response, 1477070965);
If you only can redirect to one regular page by it's
uid, you always can redirect to complexer URLs by creating a special page which is anLink to external URLwhere you can insert any kind of URL, even local URLs with special parameters.