Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] add the 'force_submit' option in FormType#6353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletionsreference/forms/types/form.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ on all types for which ``FormType`` is the parent.
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `extra_fields_message`_ |
| | - `force_submit`_ |
| | - `inherit_data`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
Expand DownExpand Up@@ -94,6 +95,62 @@ The actual default value of this option depends on other field options:

.. include:: /reference/forms/types/options/extra_fields_message.rst.inc

force_submit
~~~~~~~~~~~~

.. versionadded:: 3.1
The ``force_submit`` option was introduced in Symfony 3.1.

**type**: ``bool`` **default**: ``false``

By default when an array of data is built from request parameters in a
:class:`Symfony\\Component\\Form\\RequestHandlerInterface` the name of the form
must match a parameter key so the data can be submitted to it.

This option allow request handlers to force the submission of data to a form
when its name is not among the request parameters.

.. code-block:: php

// Normal submission
$request->request->set('my_form' => array(
'name' => 'John Doe',
'email' => 'john@foo.com',
),
);

$form = $formFactory->createNamedBuilder('my_form')
->add('name')
->add('email', EmailType::class)
->getForm();

$form->handleRequest($request);

// Forced submission
$request->request->set('name', 'John Doe');
$request->request->set('email', 'john@foo.com');

$form = $formFactory->createNamedBuilder('my_form', null, array(
'force_submit' => true,
))
->add('name')
->add('email', EmailType::class)
->getForm();

$form->handleRequest($request);

.. note::

This option is meant to be used with root forms such as default one,
or custom form types.
If this option is true in a nested form or field, it will have no
effect on the submission process.

.. tip::

This can be useful when using an API as you don't need to nest the data
in an array with the form name as key.

.. include:: /reference/forms/types/options/inherit_data.rst.inc

.. include:: /reference/forms/types/options/invalid_message.rst.inc
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp