Goranov
Goranov

Reputation: 385

Symfony2 - Reset form field after submission

I wonder whether there is a simple way to reset one of the form fields after form submission and then pass the form to the view - to render the same form but one of the field will be with it's default value. Something like:

$form = $this->createForm('MyForm');
$form->handleRequest($request);
if ($form->isValid()) {
    // do something
    // ...

    // reset one of the form field to it's default value
    // something like:
    // $form->field->reset() or
    // $form->field->setValue('');
}

return array(
    'form' => $form->createView(),
);

Thanks!

Upvotes: 2

Views: 1948

Answers (1)

COil
COil

Reputation: 7596

You can use:

$form->get('field')->submit($defaultValue);

Check out the doc.

Upvotes: 1

Related Questions