Form.button ViewHelper <f:form.button>

This ViewHelper creates a <button> HTML element within the Form ViewHelper <f:form>.

Unlike the Form.submit ViewHelper <f:form.submit>, the Form.button ViewHelper can contain HTML content — for example, an icon.

By using the type argument, you can create button types other than submit, such as button or reset.

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

A Fluid form with a submit button containing an icon

You can use the <f:form.button> ViewHelper within an Extbase form to render a <button type="submit"> element that allows HTML content.

This is especially useful when you want to include custom elements inside the button, such as icons or styled spans.

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

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.button>
        <i class="fa fa-paper-plane"></i> Submit
    </f:form.button>
</f:form>
</html>
Copied!

You can use the same Extbase controller as in the example A Fluid form with a single submit button, which uses the <f:form.submit> ViewHelper.

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 buttons of different types

The <f:form.button> ViewHelper supports the type attribute, allowing you to render buttons of type submit, reset, or button. This is useful when you want to offer multiple actions within the same form, each with a distinct purpose and custom styling or icons.

Unlike <f:form.submit>, you can include inline HTML (e.g. icons, spans) in each button.

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" object="{comment}" objectName="comment" method="post">
    <label for="tx-comment-content">Message:</label>
    <f:form.textarea property="content" id="tx-comment-content" rows="6" cols="50" />

    <f:form.button type="submit" name="action" value="save">
        <i class="fa fa-save" aria-hidden="true"></i> Save
    </f:form.button>

    <f:form.button type="reset">
        <i class="fa fa-undo" aria-hidden="true"></i> Reset
    </f:form.button>

    <f:form.button type="button" name="preview" value="1" onclick="alert('Preview not implemented!')">
        <i class="fa fa-eye" aria-hidden="true"></i> Preview
    </f:form.button>
</f:form>
</html>
Copied!

A single Extbase controller action can be used to differentiate the submitted action based on the button name or value.

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

namespace Vendor\MyExtension\Controller;

use MyVendor\MyExtension\Domain\Model\Comment;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class CommentController extends ActionController
{
    public function submitAction(Comment $comment, string $action): ResponseInterface
    {
        switch ($action) {
            case 'save':
                // Save logic here
                $this->addFlashMessage('Comment saved!');
                return $this->redirect('edit');

            case 'preview':
                // Assign preview-related data and render the same view
                $this->view->assign('preview', true);
                $this->view->assign('comment', $comment);
                return $this->htmlResponse();

            default:
                $this->addFlashMessage('Unknown action');
                return $this->redirect('edit');
        }
    }
}
Copied!

A button with additional HTML5 attributes

The <f:form.button> ViewHelper allows you to pass through standard HTML5 button attributes such as disabled, formmethod, and formnovalidate.

This is useful when you need more control over how the button behaves in relation to form submission and validation.

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" method="post">
    <f:form.button type="reset"
                   name="cancel"
                   value="cancel"
                   disabled="disabled"
                   formmethod="post"
                   formnovalidate="formnovalidate">
        Cancel
    </f:form.button>
</f:form>
</html>
Copied!

A button with accessibility attributes

The <f:form.button> ViewHelper supports accessibility attributes like aria-label, aria-disabled, or aria-describedby.

These attributes are passed directly to the rendered <button> tag, allowing you to make your forms more accessible for assistive technologies such as screen readers.

For convenience, you can also use the aria attribute and pass an array to it.

Fluid will automatically generate the corresponding aria-* attributes based on the key-value pairs in the array.

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" object="{comment}" objectName="comment" method="post">
    <label for="tx-comment-content">Message:</label>
    <f:form.textarea property="content" id="tx-comment-content" rows="6" cols="50" />
    <p id="commentHint" class="form-text">
        Press the send button to submit your comment.
    </p>

    <f:form.button type="submit" aria="{label: 'Send comment', describedby: 'commentHint'}">
        <i class="fa fa-paper-plane" aria-hidden="true"></i> Send
    </f:form.button>
</f:form>
</html>
Copied!

Arguments of the form.button 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.

type

type
Type
string
Default
'submit'
Specifies the type of button (e.g. "button", "reset" or "submit")

value

value
Type
mixed
Value of input tag