Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4005b8f

Browse files
committed
Reword
1 parent a92442a commit 4005b8f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

form/direct_submit.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ control over when exactly your form is submitted and what data is passed to it::
3434
]);
3535
}
3636

37+
The list of fields submitted with the ``submit()`` method must be the same as
38+
the fields defined by the form class. Otherwise, you'll see a form validation error::
39+
40+
public function new(Request $request): Response
41+
{
42+
// ...
43+
44+
if ($request->isMethod('POST')) {
45+
// '$json' represents payload data sent by React/Angular/Vue
46+
// the merge of parameters is needed to submit all form fields
47+
$form->submit(array_merge($json, $request->request->all()));
48+
49+
// ...
50+
}
51+
52+
// ...
53+
}
54+
3755
.. tip::
3856

3957
Forms consisting of nested fields expect an array in
@@ -59,12 +77,3 @@ control over when exactly your form is submitted and what data is passed to it::
5977

6078
// 'email' and 'username' are added manually to force their validation
6179
$form->submit(array_merge(['email' => null, 'username' => null], $request->request->all()), false);
62-
63-
.. caution::
64-
65-
When submitting a form via a "POST" request and manually submitting the form
66-
with ``submit()``, ensure that list of fields in payload equals the list of validated
67-
fields in FormType class - in other case the form validation will fail.
68-
69-
//'json' represents payload data (used frequently by api client as React/Angular/Vue etc.)
70-
$form->submit(array_merge($json, $request->request->all()));

0 commit comments

Comments
 (0)