Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony: form_enctype deprecated

Tags:

php

symfony

Currently I have following code in symfony 2 and I want to upgrade it to symfony 3. I get this deprecation warning to use form_start instead of form_enctype. How can I change the following code with form_start?

View:

<form method="post" {{ form_enctype(decryptionForm) }}>
                                {{ form_widget(decryptionForm) }}
                                {{ submit_widget }}
                            </form>

Controller

$form = new DecryptionForm();
        $this->setContext(array(
            'decryptionForm' => $form->createView()
        ));

Form

$builder = $this->getFormBuilder();
        $form = $builder
            ->add(self::FORM_KEY_SAMPLECASE, 'hidden', array())
            ->add(self::FORM_KEY_DECRKEYFILE, 'file', array(
                'constraints' => array(new NotBlank()),
                'label' => "private_key"
            ))
            ->add("Submit", 'submit')
            ->getForm();
like image 873
asdfkjasdfjk Avatar asked Jun 14 '16 15:06

asdfkjasdfjk


2 Answers

You can replace

<form method="post" {{ form_enctype(decryptionForm) }}>

by

{{ form_start(decryptionForm) }}

and

</form>

by

{{ form_end(decryptionForm) }}
like image 92
jiboulex Avatar answered Nov 01 '22 07:11

jiboulex


As Alvin mentioned replace form opening and closing to symfony provided functions: {{ form_start(decryptionForm) }} and {{ form_end(decryptionForm) }}. Now Symfony handles enctype by default.

like image 40
Ignas Damunskis Avatar answered Nov 01 '22 06:11

Ignas Damunskis