Typo3 frontend plugin, use _POST data in the controller

3.1k Views Asked by At

I wrote a very simple extension in typo3 v7.6.11 with the extension builder where a visitor can ask for a taxi-ride.

everything works, only that I need to make the request more appealing by asking the pick-up point and the drop-off point ... that request goes to the actual form like this in the template (requestPid is the id of the page with the form):

<f:form pageUid="{settings.additional.requestPid}" action="form" name="request" object="{Request}">
  <f:render partial="Ticket/RequestNewFields" />
  <f:form.submit value="{f:translate(key: 'tx_wmnltickets_domain_model_ticket.admin.continue')}" />
</f:form>

but the formAction in the controler doesn't actually ask anything from the model (getArguments() I tried);

/**
 * action form
 * 
 * @return void
 */
public function formAction() {
    $this->request->getArguments();
}

the request does send the $_POST but I see no way to get it into the form ... if you'd like to see more code to understand, just ask, I don't know what you'd be looking for ...

2

There are 2 best solutions below

10
On BEST ANSWER

Your form action should has the request parameter from you form:

/**
 * action form
 * 
 * @param array $request
 *
 * @return void
 */
 public function formAction($request) {
 }

Then you can access the data with $request['origin']

I'm not sure if the variable $request is allowed as argument. Maybe you must rename it in the function and in your fluid template if it doesn't work.

2
On

Did you create the extension with the builder? The easiest way is to create the fields (pickup-point, dropoff-point) in the builder, then create a createAction or newAction (not sure how it is called in the builder). It will create the template for the createAction where you can just copy/paste the <f:form...

There is a way to access directly POST/GET parameters (It is not recomended to use it directly when you can make it with the clean extbase way):

$myVar = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('myVar');