Skip to content

Commit f461e36

Browse files
committed
[TASK] Update f:form.submit ViewHelper page
Releases: main, 13.4
1 parent 7e73abf commit f461e36

File tree

6 files changed

+162
-16
lines changed

6 files changed

+162
-16
lines changed

Documentation/Global/Form/Index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ data objects.
4444
For example, user could add a comment in such a form:
4545

4646
.. literalinclude:: _codesnippets/_CommentForm.html
47-
:caption: packages/my_extension/Resources/Private/Templates/Comment/_CommentForm.html
47+
:caption: packages/my_extension/Resources/Private/Templates/Comment/CommentForm.html
4848

4949
The Extbase Controller action displaying the form then creates the Domain object
5050
and passes it to the view. In the Fluid template above we use argument

Documentation/Global/Form/Submit.rst

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,85 @@ Form.submit ViewHelper `<f:form.submit>`
99

1010
.. typo3:viewhelper:: form.submit
1111
:source: ../../Global.json
12-
:display: tags,description,gitHubLink,arguments
12+
:display: tags
13+
:noindex:
14+
15+
Creates a submit button (`<input type="submit"`) within a
16+
`Form ViewHelper <f:form> <https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-form>`_.
17+
18+
.. note::
19+
If you you need a `<button>` with extended HTML content, use the
20+
`Form.button ViewHelper <f:form.button> <https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-form-button>`_
21+
instead.
22+
23+
.. typo3:viewhelper:: form.submit
24+
:source: ../../Global.json
25+
:display: gitHubLink
26+
:noindex:
27+
28+
.. contents:: Table of contents
1329

1430
.. _typo3-fluid-form-submit-example:
1531

16-
Examples
17-
========
32+
A Fluid form with a single submit button
33+
========================================
34+
35+
You can use the `<f:form.submit value="Submit!">` button within an Extbase
36+
form to display a `<input type="submit" value="Submit!">` button.
37+
38+
When the user clicks the button, the action specified by the surrounding
39+
`<f:form> <https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-form>`_
40+
is called.
41+
42+
.. tabs::
1843

19-
Defaults
20-
--------
44+
.. group-tab:: Fluid
2145

22-
::
46+
.. literalinclude:: _codesnippets/_FormSubmit.html
47+
:caption: packages/my_extension/Resources/Private/Templates/Comment/Edit.html
2348

24-
<f:form.submit value="Send Mail" />
49+
.. group-tab:: Controller
2550

26-
Output::
51+
Then controller action can then look like this:
2752

28-
<input type="submit" />
53+
.. literalinclude:: _codesnippets/_SubmitController.php
54+
:caption: packages/my_extension/Classes/Controller/CommentController.php
2955

30-
Dummy content for template preview
31-
----------------------------------
56+
.. _typo3-fluid-form-submit-example-multiple:
3257

33-
::
58+
A Fluid form with multiple submit buttons
59+
=========================================
3460

35-
<f:form.submit name="mySubmit" value="Send Mail"><button>dummy button</button></f:form.submit>
61+
When you want to offer different actions it can be helpful to use multiple
62+
submit buttons with different labels:
3663

37-
Output::
64+
.. tabs::
3865

39-
<input type="submit" name="mySubmit" value="Send Mail" />
66+
.. group-tab:: Fluid
67+
68+
.. literalinclude:: _codesnippets/_FormSubmitMultiple.html
69+
:caption: packages/my_extension/Resources/Private/Templates/Comment/Edit.html
70+
71+
.. group-tab:: Controller
72+
73+
Then controller action can then look like this:
74+
75+
.. literalinclude:: _codesnippets/_SubmitMultipleController.php
76+
:caption: packages/my_extension/Classes/Controller/CommentController.php
77+
78+
.. note::
79+
All rendered buttons will be rendered as `<input type="submit"`.
80+
If you need a button with a different type then "submit" use the
81+
`Form.button ViewHelper <f:form.button> <https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-form-button>`_
82+
instead.
83+
84+
.. _typo3-fluid-form-submit-arguments:
85+
86+
Arguments of the form.submit ViewHelper
87+
=======================================
88+
89+
.. include:: /_Includes/_ArbitraryArguments.rst.txt
90+
91+
.. typo3:viewhelper:: form.submit
92+
:source: /Global.json
93+
:display: arguments-only
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
2+
data-namespace-typo3-fluid="true">
3+
<f:form action="submit" controller="Comment" objectName="comment" object="{comment}" method="post">
4+
<label for="tx-blogexample-content">Message:</label>
5+
<f:form.textarea property="content" id="tx-blogexample-content" rows="8" cols="46"/>
6+
<f:form.submit value="Submit"/>
7+
</f:form>
8+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
2+
data-namespace-typo3-fluid="true">
3+
<f:form action="submit" controller="MyController" objectName="comment" object="{comment}" method="post">
4+
<label for="tx-blogexample-content">Message:</label>
5+
<f:form.textarea property="content" id="tx-blogexample-content" rows="8" cols="46"/>
6+
<f:form.submit name="submitButton" value="Submit"/>
7+
<f:form.submit name="cancelButton" value="Cancel"/>
8+
<f:form.submit name="spellingButton" value="Check spelling"/>
9+
</f:form>
10+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MyVendor\MyExtension\Controller;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use T3docs\BlogExample\Domain\Model\Comment;
9+
use T3docs\BlogExample\Domain\Repository\CommentRepository;
10+
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
11+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
12+
13+
class CommentController extends ActionController
14+
{
15+
public function __construct(
16+
protected readonly CommentRepository $commentRepository,
17+
) {}
18+
19+
public function submitAction(Comment $comment): ResponseInterface
20+
{
21+
$this->commentRepository->update($comment);
22+
$this->addFlashMessage('Your comment was saved');
23+
return $this->redirect('show');
24+
}
25+
26+
// Other actions
27+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MyVendor\MyExtension\Controller;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use T3docs\BlogExample\Domain\Model\Comment;
9+
use T3docs\BlogExample\Domain\Repository\CommentRepository;
10+
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
11+
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
12+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
13+
14+
class CommentController extends ActionController
15+
{
16+
public function __construct(
17+
protected readonly CommentRepository $commentRepository,
18+
) {}
19+
20+
public function submitAction(
21+
Comment $comment,
22+
bool $cancelButton = false,
23+
bool $spellingButton = false,
24+
): ResponseInterface
25+
{
26+
if ($cancelButton) {
27+
$this->addFlashMessage(
28+
'Your comment was NOT saved, you pressed the cancel button',
29+
'Attention',
30+
ContextualFeedbackSeverity::WARNING
31+
);
32+
return $this->redirect('show');
33+
}
34+
if ($spellingButton) {
35+
if (!$this->mySpellCheckService->check($comment->getMessage())) {
36+
$this->addFlashMessage('There are spelling errors. ');
37+
}
38+
return $this->redirect('edit', null, null, ['comment' => $comment]);
39+
}
40+
// Form was submitted by submit button or for example by JavaScript
41+
$this->commentRepository->update($comment);
42+
$this->addFlashMessage('Your comment was saved');
43+
return $this->redirect('show');
44+
}
45+
46+
// Other actions
47+
}

0 commit comments

Comments
 (0)