Skip to content
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
23 changes: 23 additions & 0 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,29 @@ to the ``form()`` or the ``form_start()`` helper:
a PUT, PATCH or DELETE request. Read the cookbook chapter
":doc:`/cookbook/routing/method_parameters`" for more information.

.. note::

Now that the ``createForm()`` method requires the FQCN, you can no longer pass in *dynamic* ``__construct()`` arguments. This is not to be confused with :ref:`form-as-services`. To get
around this, you will need to create the default options in the form class ``configureOptions()`` method::

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('username', TextType::class, array('required' => $options['username_required']));
$builder->add('password', PasswordType::class, array('required' => $options['password_required']));
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'username_required' => true,
'password_required' => false,
));
}

.. index::
single: Forms; Creating form classes

Expand Down