0

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 ...

andreas
  • 16,357
  • 12
  • 72
  • 76
webman
  • 1,117
  • 15
  • 41

2 Answers2

2

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.

René Pflamm
  • 3,273
  • 17
  • 29
  • This is the preferred and recommended way to transfer arguments to any action. It causes the parameter to be correctly isolated in a sub-scope of URL arguments in GET as well as POST. One should in nearly all cases stay away from accessing `$this->request->getArguments()` in the controller (there's a much longer explanation why but essentially: the arguments there are not validated or converted). So in *every* single case where you need your controllers to pass/receive arguments: declare the arguments correctly on the controller and use those names when passing the arguments. – Claus Due Sep 07 '16 at 11:35
  • `request` is not a reserved argument name but for reasons of clarity it should be avoided as name of a DTO (data transfer object). – Claus Due Sep 07 '16 at 11:36
  • I used newTicket as variable, just to be sure ... but how do I access `$newTicket['origin']` in my fluid template ?? the only way the variable seems accessible is with `$this->view->assign('ticket', $newTicket);` in function formAction ... but no values ... – webman Sep 13 '16 at 08:40
  • Thats correct, assign the variable to the view (fluid) than you can access origin in fluid by using ```{ticket.origin}``` – René Pflamm Sep 13 '16 at 08:42
  • there must be some kind of typo somewhere ... it all seems proper but with debug the `ticket` remains `NULL` ... very frustrating – webman Sep 13 '16 at 08:55
  • Have you cleared the cache after renaming the variable? – René Pflamm Sep 13 '16 at 08:56
  • By the way: If an answer helped you, please mark the answer as helped. – René Pflamm Sep 13 '16 at 08:58
  • the cache did not help ... what about in the f:form I use property instead of name ... could that complicate ? (by the way, of course your answers help, I just did not resolve yet) – webman Sep 13 '16 at 09:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/123226/discussion-between-rene-pflamm-and-webman). – René Pflamm Sep 13 '16 at 09:16
  • Great René, I was really getting frustrated, a bit of coaching ... whenever ... you have my email now, I live near gearge clooney !! – webman Sep 13 '16 at 09:59
0

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');
nbar
  • 6,028
  • 2
  • 24
  • 65
  • thx 4 the intrest: yes its done with the builder, but its kind of cross-over, I have this small form with two fields (pickup-point, dropoff-point) and the full form which starts with these two and has another 8 or 10 ... – webman Sep 06 '16 at 15:49
  • I just need these two to be transprorted to the full form, there its going to be registered ... – webman Sep 06 '16 at 15:51