Form.submit ViewHelper <f:form.submit>

Creates a submit button (<input type="submit"...>) within a Form ViewHelper <f:form>.

Go to the source code of this ViewHelper: Form\SubmitViewHelper.php (GitHub).

A Fluid form with a single submit button

You can use the <f:form.submit value="Submit!"> button within an Extbase form to display a <input type="submit" value="Submit!"> button.

When the user clicks the button, the action specified by the surrounding <f:form> is called.

packages/my_extension/Resources/Private/Templates/Comment/Edit.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
      data-namespace-typo3-fluid="true">
    <f:form action="submit" controller="Comment" objectName="comment" object="{comment}" method="post">
        <label for="tx-blogexample-content">Message:</label>
        <f:form.textarea property="content" id="tx-blogexample-content" rows="8" cols="46"/>
        <f:form.submit value="Submit"/>
    </f:form>
</html>
Copied!

The controller action can then look like this:

packages/my_extension/Classes/Controller/CommentController.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Controller;

use Psr\Http\Message\ResponseInterface;
use T3docs\BlogExample\Domain\Model\Comment;
use T3docs\BlogExample\Domain\Repository\CommentRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class CommentController extends ActionController
{
    public function __construct(
        protected readonly CommentRepository $commentRepository,
    ) {}

    public function submitAction(Comment $comment): ResponseInterface
    {
        $this->commentRepository->update($comment);
        $this->addFlashMessage('Your comment was saved');
        return $this->redirect('show');
    }

    // Other actions
}
Copied!

A Fluid form with multiple submit buttons

When you want to offer different actions, it can be helpful to use multiple submit buttons with different labels:

packages/my_extension/Resources/Private/Templates/Comment/Edit.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
      data-namespace-typo3-fluid="true">
    <f:form action="submit" controller="MyController" objectName="comment" object="{comment}" method="post">
        <label for="tx-blogexample-content">Message:</label>
        <f:form.textarea property="content" id="tx-blogexample-content" rows="8" cols="46"/>
        <f:form.submit name="submitButton" value="Submit"/>
        <f:form.submit name="cancelButton" value="Cancel"/>
        <f:form.submit name="spellingButton" value="Check spelling"/>
    </f:form>
</html>
Copied!

The controller action can then look like this:

packages/my_extension/Classes/Controller/CommentController.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Controller;

use Psr\Http\Message\ResponseInterface;
use T3docs\BlogExample\Domain\Model\Comment;
use T3docs\BlogExample\Domain\Repository\CommentRepository;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class CommentController extends ActionController
{
    public function __construct(
        protected readonly CommentRepository $commentRepository,
    ) {}

    public function submitAction(
        Comment $comment,
        bool $cancelButton = false,
        bool $spellingButton = false,
    ): ResponseInterface {
        if ($cancelButton) {
            $this->addFlashMessage(
                'Your comment was NOT saved, you pressed the cancel button',
                'Attention',
                ContextualFeedbackSeverity::WARNING,
            );
            return $this->redirect('show');
        }
        if ($spellingButton) {
            if (!$this->mySpellCheckService->check($comment->getMessage())) {
                $this->addFlashMessage('There are spelling errors. ');
            }
            return $this->redirect('edit', null, null, ['comment' => $comment]);
        }
        // Form was submitted by submit button or for example by JavaScript
        $this->commentRepository->update($comment);
        $this->addFlashMessage('Your comment was saved');
        return $this->redirect('show');
    }

    // Other actions
}
Copied!

Arguments of the form.submit ViewHelper

additionalAttributes

additionalAttributes
Type
array
Additional tag attributes. They will be added directly to the resulting HTML tag.

aria

aria
Type
array
Additional aria-* attributes. They will each be added with a "aria-" prefix.

data

data
Type
array
Additional data-* attributes. They will each be added with a "data-" prefix.

name

name
Type
string
Name of input tag

property

property
Type
string
Name of Object Property. If used in conjunction with <f:form object="...">, the "name" property will be ignored, while "value" can be used to specify a default field value instead of the object property value.

value

value
Type
mixed
Value of input tag