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

Skip to content

[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all 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 deletions reference/forms/types/form.rst
Original file line number Diff line number Diff 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 Down Expand 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' => '[email protected]',
),
);

$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', '[email protected]');

$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