Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] add 'force_submit' option to FormType#18053

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@HeahDude
Copy link
Contributor

QA
Branchmaster
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#16491
LicenseMIT
Doc PRsymfony/symfony-docs#6353

@HeahDude
Copy link
ContributorAuthor

It would be better if we could use$form->getConfig()->getForceSubmit() but changingFormConfigInterface would break BC.


$this->setRequestData($method,array());

$form->expects($this->once())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think you should add awith() block here.

@webmozart
Copy link
Contributor

Thanks for working on this@HeahDude! :)

@HeahDude
Copy link
ContributorAuthor

@webmozart alright, comments addressed!

@webmozart
Copy link
Contributor

Looks good, thanks@HeahDude! :) 👍

Is anybody taking care of the failed tests?

@HeahDude
Copy link
ContributorAuthor

@webmozart thanks!

I think appveyor was fixed by@nicolas-grekas in#18054 and for travis on php 7@xabbuh should have fixed it in#18037.

@xabbuh
Copy link
Member

Yes, failures are unrelated.

@xabbuh
Copy link
Member

Imo this needs to be added to the changelog (to document the new feature) and to the upgrade file as (as people will have to update their own request handler if they built one).

@HeahDude
Copy link
ContributorAuthor

Ok.

Status: Needs Work

@HeahDudeHeahDudeforce-pushed thefeature-form-force_submit branch from7748f5e tod354997CompareMarch 12, 2016 01:05
HeahDude added a commit to HeahDude/symfony-docs that referenced this pull requestMar 12, 2016
related tosymfony/symfony#18053Document the new option ‘force_submit’ added to FormType in 3.1It allows request handlers to submit data that does not hold the formname.
@HeahDudeHeahDudeforce-pushed thefeature-form-force_submit branch fromd354997 to9ead4acCompareMarch 12, 2016 06:48
HeahDude added a commit to HeahDude/symfony-docs that referenced this pull requestMar 12, 2016
related tosymfony/symfony#18053Document the new option ‘force_submit’ added to FormType in 3.1It allows request handlers to submit data that does not hold the formname.
@HeahDudeHeahDude changed the title[WIP] [Form] add 'force_submit' option[Form] add 'force_submit' option to FormTypeMar 12, 2016
@HeahDude
Copy link
ContributorAuthor

Status: Needs Review

in`ResizeFormListener::preSubmit` method has been deprecated and will be
removed in Symfony 4.0.
* A new "force_submit" option has been added to allow request handlers to
submit a form even if its name is not a key of the submitted data array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As the new option doesn't force the user to do anything when upgrading it shouldn't be added to the upgrade file.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed, thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh sorry, we need to add it to the upgrade file as one needs to change their custom request handlers. Please excuse the confusion.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is not mandatory. The option is just available for anyone who wants to use it, but is totally transparent for pure BC.

Final words ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What do you think@webmozart?

closessymfony#16491.Add a `force_submit` option to FormType with default false,allowing request handlers to submit a form even if its nameis not a key of the submitted data array.
@HeahDudeHeahDudeforce-pushed thefeature-form-force_submit branch from9ead4ac to85bf807CompareMarch 13, 2016 22:17
HeahDude added a commit to HeahDude/symfony-docs that referenced this pull requestMar 13, 2016
related tosymfony/symfony#18053Document the new option ‘force_submit’ added to FormType in 3.1It allows request handlers to submit data that does not hold the formname.
@webmozart
Copy link
Contributor

Status: Reviewed

👍

@javiereguiluz
Copy link
Member

I know I'm very late to this PR ... but I have some concerns about theforce_submit name. Without reading the code or the docs,force_submit can be understood as"send the form even if it contains errors","send the form even if some field is missing","send the form even if the CSRF token doesn't match","keep retrying form submission until there is no error", etc.

But this option in fact just removes the form name from the submitted values. Instead ofuser[name] you can usename.

@HeahDude
Copy link
ContributorAuthor

@javiereguiluz Hopefully one would read the docs before using a new option :) If you think otherwise, do you have a suggestion ?

@webmozart
Copy link
Contributor

@javiereguiluz That's a very good point, thanks for pointing it out. So in effect what we are controlling is:

// When$form->handleRequest($request);// force_submit=true: only submit if $form->getName() present in request$form->submit($request->request->get($form->getName()));// force_submit=true: submit even if $form->getName() not present in request$form->submit($request->request->all());

What aboutsubmit_every_request?

As seen in this snippet, another difference is that - with the option set - we do not submit the data of the form, but the complete request. Does this make sense? Shouldn't we rather submitnull here?

ping@guilhermeblanco

@webmozart
Copy link
Contributor

Furthermore, do wereally need this? So far,@guilhermeblanco was the only one who ever needed this feature, and it can easily be fixed by implementing the functionality of the request handler yourself in the controller (or as anotherRequestHandlerInterface implementation, if it needs to be reused).

@xabbuh
Copy link
Member

@webmozart Afaics#12528 would (at least partly) be solvable with this change too.

@HeahDude
Copy link
ContributorAuthor

Yes I agree it's more accurate to usesubmit_every_request.

What aboutforce_submit_request ?

@guilhermeblanco
Copy link
Contributor

@webmozart I think the namesubmit_every_request is better than originally proposed one.
Also, the motivation is mainly about having a GET request with an un-named form, where every regular request should submit the form.
Now taking the GET call together with the form with fields that have default values (empty_data), let's say page=1, perPage=50. Hitting the controller without submitting anything should still submit the form, even though it doesn't have any form data. Also, $form->isValid() must be true (which is not right now because $form->isSubmitted() is false). No matter what we discuss, this is a valid situation where I could force submission.

There's an alternative, implementing my own RequestHandlerInterface, but still, it takes a couple time to digest what you did wrong when working on a day by day basis and experiencing this issue.

@HeahDude
Copy link
ContributorAuthor

What about addingFormConfig::getSubmitEveryRequest() then pushing the method to theFormConfigInterface in 3.4 ? It looks more like a "hack" actually.

@HeahDude
Copy link
ContributorAuthor

I agree it can be useful for API in general and API with GET in particular.

@HeahDude
Copy link
ContributorAuthor

What's the final call on this ? Changing the name is easy to get done for tomorrow :)

@javiereguiluz
Copy link
Member

@HeahDude Bernhard commented the following:

As seen in this snippet, another difference is that - with the option set - we do not submit the data of
the form, but the complete request. Does this make sense? Shouldn't we rather submit null here?

So, if this option is about submitting the request, why not calling itsubmit_request ?

@HeahDude
Copy link
ContributorAuthor

I agree with all the reasoning here, I would just say I'm not against your proposal, but I don't find it explicit since all form get submitted through request then I go in circle again:

  • force_submit_request (because data keys mismatch) orforce_submit_data
  • submit_all_request orsubmit_every_request
  • submit_as_root
  • submit_unmapped
  • submit_no_name
  • submit_anonymous
  • anonymous_form
  • 'force_submit_anonymous`

??

@webmozart
Copy link
Contributor

I think we're overengineering. This use case can be solved as simply as:

$form =$this->createForm(/* ... */);$form->submit($request->query->all());if ($form->isValid()) {// ...}

Just replacehandleRequest() bysubmit(). There's nothing we need to change as far as I can tell. :)

@HeahDude
Copy link
ContributorAuthor

I may be wrong but the point of this PR is that we cannot do it if the form name is not the key holding the data to submit, because the request handler will not map it, right ?

@HeahDude
Copy link
ContributorAuthor

@webmozart What do you think about having in 4.0 some clear equivalence:

// Does not work$dataToSubmit = $form->getViewData();$form->submit($dataToSubmit); // would submit pre set data// Works$emptyData = $form->getConfig()->getEmptyData();$form->submit($emptyData); // <=> $form->submit(null);

Don't get me wrong, I'm not talking about modifying the way APIs work but about compatibility of dataset and data mapping and the way view data is handled throw the global form lifecycle.

@webmozart
Copy link
Contributor

The request handler is simply a more user friendly interface to submit(). If you have more elaborate use cases, using submit() directly is simple enough.

compatibility of dataset and data mapping and the way view data is handled throw the global form lifecycle.

What do you mean? What do you see that should be improved?

@HeahDude
Copy link
ContributorAuthor

Thanks for your response :)

I mean currently$viewData unless using transformers is equal to model data.

My guess is that it should match the real view value:compound ? array : string

@HeahDude
Copy link
ContributorAuthor

On second thought to be able to do that, the data mapping should be done with normalized data, shouldn't it ?

@HeahDudeHeahDude deleted the feature-form-force_submit branchApril 9, 2016 13:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@HeahDude@webmozart@xabbuh@javiereguiluz@guilhermeblanco@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp