Form.submit ViewHelper <f:form.submit>
Creates a submit button (<input type="submit"...>
) within a
Form ViewHelper <f:form>.
Note
If you you need a <button>
with extended HTML content, use the
Form.button ViewHelper <f:form.button>
instead.
Go to the source code of this ViewHelper: Form\SubmitViewHelper.php (GitHub).
Table of contents
A Fluid form with a single submit button
You can use the <f:
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.
<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>
The controller action can then look like this:
<?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
}
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:
<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>
The controller action can then look like this:
<?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
}
Note
All rendered buttons will be rendered as <input type="submit"...>
.
If you need a button with a different type than "submit", use the
Form.button ViewHelper <f:form.button>
instead.
Arguments of the form.submit ViewHelper
Allows arbitrary arguments
This ViewHelper allows you to pass arbitrary arguments not defined below
directly to the HTML tag created. This includes custom data-
arguments.
additionalAttributes
-
- Type
- array
Additional tag attributes. They will be added directly to the resulting HTML tag.
aria
-
- Type
- array
Additional aria-* attributes. They will each be added with a "aria-" prefix.
data
-
- Type
- array
Additional data-* attributes. They will each be added with a "data-" prefix.
name
-
- Type
- string
Name of input tag
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
-
- Type
- mixed
Value of input tag