Skip to content

Commit 4b259cc

Browse files
MrYamousjaviereguiluz
authored andcommitted
Replace render by new renderForm method in form documentation
1 parent a6e8143 commit 4b259cc

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

form/direct_submit.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ control over when exactly your form is submitted and what data is passed to it::
2929
}
3030
}
3131

32-
return $this->render('task/new.html.twig', [
33-
'form' => $form->createView(),
34-
]);
32+
return $this->renderForm('task/new.html.twig', $form);
3533
}
3634

3735
The list of fields submitted with the ``submit()`` method must be the same as

form/dynamic_form_modification.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,7 @@ your application. Assume that you have a sport meetup creation controller::
534534
// ... save the meetup, redirect etc.
535535
}
536536

537-
return $this->render(
538-
'meetup/create.html.twig',
539-
['form' => $form->createView()]
540-
);
537+
return $this->renderForm('meetup/create.html.twig', $form);
541538
}
542539

543540
// ...

form/form_collections.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ In your controller, you'll create a new form from the ``TaskType``::
164164
// ... do your form processing, like saving the Task and Tag entities
165165
}
166166

167-
return $this->render('task/new.html.twig', [
168-
'form' => $form->createView(),
169-
]);
167+
return $this->renderForm('task/new.html.twig', $form);
170168
}
171169
}
172170

forms.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,15 @@ to build another object with the visual representation of the form::
277277

278278
$form = $this->createForm(TaskType::class, $task);
279279

280-
return $this->render('task/new.html.twig', [
281-
'form' => $form->createView(),
282-
]);
280+
return $this->renderForm('task/new.html.twig', $form);
283281
}
284282
}
285283

284+
.. versionadded:: 5.3
285+
286+
The ``renderForm`` method was introduced in Symfony 5.3, allowing to
287+
return 422 HTTP status code if an invalid form is submitted.
288+
286289
Then, use some :ref:`form helper functions <reference-form-twig-functions>` to
287290
render the form contents:
288291

@@ -405,9 +408,7 @@ written into the form object::
405408
return $this->redirectToRoute('task_success');
406409
}
407410

408-
return $this->render('task/new.html.twig', [
409-
'form' => $form->createView(),
410-
]);
411+
return $this->renderForm('task/new.html.twig', $form);
411412
}
412413
}
413414

0 commit comments

Comments
 (0)