简体   繁体   中英

Submit form to different action with typo3 flow

I have a page with a form for creating users. A user has an hobby, which can be created on the same page by clicking on the second button which opens the page for creating a hobby. After creating the hobby, the previous user form should be shown with the user input inserted before going to the hobby page.

Is there a way to do something like with typo3 flow / fluid without using AJAX?

I tried to submit the input to a different action by clicking on the createHobby button --> The action redirects to the new hobby page, where the user can create the hobby and after creation it should redirect back to the user form with the already filled out input fields by the user .

I used...

<input type='submit' value='Create' formaction='/hobby/create' />`

to achive this, but it seems there are some problems with the uris... I get following error:

#1301610453: Could not resolve a route and its corresponding URI for the given parameters.

I think the using the attribute formaction is not a good solution for every case, as it is not supported by IE < 10 as you can see here . I think a JavaScript backport should also be considered (dynamically change the action attribute of the form when clicking on the second button, before actually submitting the form).

Concerning your error, you should not – and probably never – use direct HTML input , instead try to focus on Fluid ViewHelpers, which allow TYPO3 to create the correct HTML input.

Try this instead:

<f:form.submit value="Create" additionalAttributes="{formaction: '{f:uri.action(controller: \'hobby\', action: \'create\')}'}" />

You can make an $this->forward(...) in an initializeAction depending on an param of your action.

Lets imagine your default Form action is "create". So you need an initializeCreateAction :

public function initializeCreateAction()
{
  if ($this->arguments->hasArgument('createHobby')) {
    $createHobby = $this->request->getArgument('createHobby');
    if ($createHobby) {
      $this->forward('create', 'Hobby', NULL, $this->request->getArguments());
    }
  }
}

Now you must name your input createHobby and assign your createAction this param:

In fluid:

<f:form.button type="submit" name="createHobby" value="1">Create Hobby</f:form.button>

In your Controller:

public function createAction($formData, $createHobby = false)
{
 ...
}

您能否解释更多...显示的内容与typo3无关,我不知道您在哪里插入了typo3的哪个版本,并使用了额外的扩展名?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM