Skip to content

Call isSubmitted() before calling isValid() #7119

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 2 commits into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions components/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ method:

$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();

// ... perform some action, such as saving the data to the database
Expand All @@ -573,7 +573,7 @@ method:

$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();

// ... perform some action, such as saving the data to the database
Expand Down
2 changes: 1 addition & 1 deletion controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ For example, imagine you're processing a :doc:`form </forms>` submission::
{
// ...

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// do some sort of processing

$this->addFlash(
Expand Down
2 changes: 1 addition & 1 deletion controller/upload_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Now you're ready to use this service in the controller::
{
// ...

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$file = $product->getBrochure();
$fileName = $this->get('app.brochure_uploader')->upload($file);

Expand Down
6 changes: 3 additions & 3 deletions form/direct_submit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ submissions::

$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// perform some action...

return $this->redirectToRoute('task_success');
Expand Down Expand Up @@ -63,7 +63,7 @@ method, pass the submitted data directly to
if ($request->isMethod('POST')) {
$form->submit($request->request->get($form->getName()));

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// perform some action...

return $this->redirectToRoute('task_success');
Expand Down Expand Up @@ -115,7 +115,7 @@ a convenient shortcut to the previous example::
if ($request->isMethod('POST')) {
$form->submit($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// perform some action...

return $this->redirectToRoute('task_success');
Expand Down
2 changes: 1 addition & 1 deletion form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ your application. Assume that you have a sport meetup creation controller::
$meetup = new SportMeetup();
$form = $this->createForm(new SportMeetupType(), $meetup);
$form->handleRequest($request);
if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// ... save the meetup, redirect etc.
}

Expand Down
2 changes: 1 addition & 1 deletion form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ In your controller, you'll now initialize a new instance of ``TaskType``::

$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// ... maybe do some form processing, like saving the Task and Tag objects
}

Expand Down
2 changes: 1 addition & 1 deletion form/multiple_buttons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In your controller, use the button's
:method:`Symfony\\Component\\Form\\ClickableInterface::isClicked` method for
querying if the "Save and add" button was clicked::

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// ... perform some action, such as saving the task to the database

$nextAction = $form->get('saveAndAdd')->isClicked()
Expand Down
2 changes: 1 addition & 1 deletion form/without_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ an array of the submitted data. This is actually really easy::

$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
// data is an array with "name", "email", and "message" keys
$data = $form->getData();
}
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ be used to move the ``attachment`` file to a permanent location::
{
// ...

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$someNewFilename = ...

$form['attachment']->getData()->move($dir, $someNewFilename);
Expand Down
2 changes: 1 addition & 1 deletion security/acl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Creating an ACL and Adding an ACE

// ... setup $form, and submit data

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($comment);
$entityManager->flush();
Expand Down