8000 Wrong description of normalized data in FormEvents::SUBMIT · Issue #11193 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Wrong description of normalized data in FormEvents::SUBMIT #11193

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
sb-relaxt-at opened this issue Mar 20, 2019 · 9 comments
Closed

Wrong description of normalized data in FormEvents::SUBMIT #11193

sb-relaxt-at opened this issue Mar 20, 2019 · 9 comments
Labels
Form hasPR A Pull Request has already been submitted for this issue. Keep open

Comments

@sb-relaxt-at
Copy link

There seems to be an error in the documentation about form events. Given our limited testing we see the following behaviour in Symfony 4.2:

FormEvents::SUBMIT / Normalized data
This contains the same data as in FormEvents::POST_SET_DATA (so it is yet not updated) - whereas the docs say "Data from the request reverse-transformed from the request using a view transformer" (which indicates that this contains the new value from the request).

FormEvents::POST_SUBMIT / Normalized data
As a subsequent error the description of FormEvents::POST_SUBMIT ("Same as in FormEvents::SUBMIT") is wrong, as it contains the data from the request.

@xabbuh
Copy link
Member
xabbuh commented Mar 20, 2019

I'd say this is rather related to your code then as both events will actually receive the submitted data but not the initial data.

@xabbuh xabbuh added the Form label Mar 20, 2019
@sb-relaxt-at
Copy link
Author
sb-relaxt-at commented Mar 20, 2019

Whereas the data received via the event is the submitted data, this is not true for the data retrieved from the form. We have prepared a minimal working example. If you use this type and submit a change from "initial_data" to "request_data" you will receive the following output:

FormEvents::PRE_SUBMIT

"request_data" // $event->getData()
"initial_data" // $event->getForm()->getData()
"initial_data" // $event->getForm()->getNormData()
"initial_data" // $event->getForm()->getViewData()

FormEvents::SUBMIT

"request_data" // $event->getData()
"initial_data" // $event->getForm()->getData()
"initial_data" // $event->getForm()->getNormData() (!!!)
"initial_data" // $event->getForm()->getViewData()

FormEvents::POSTSUBMIT

"request_data" // $event->getData()
"request_data" // $event->getForm()->getData()
"request_data" // $event->getForm()->getNormData()
"request_data" // $event->getForm()->getViewData()

From my understanding this corresponds to the implementation in Form.php as the norm data of the form is updated just before dispatching FormEvents::POST_SUBMIT.

@xabbuh
Copy link
Member
xabbuh commented Mar 20, 2019

That's the expected behaviour. From your initial description I thought you were talking about the getData() method of the event as that's the method being documented here.

@sb-relaxt-at
Copy link
Author

Sorry for being ambiguous in this point. I am referring to the following description (screenshot from the docs):

The FormEvents::SUBMIT Event
image

I believe this to document getData(), getNormData() and getViewData() methods from $event->getForm().

@sb-relaxt-at
Copy link
Author

@xabbuh Could you be so kind and have another look at this issue? It's about the normalized data in the submit event (example and description in previous comments).

@xabbuh
Copy link
Member
xabbuh commented Jun 14, 2019

@sb-relaxt-at This looks indeed confusing. Though I have no idea how we could improve this.

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link
Collaborator

Hello? This issue is about to be closed if nobody replies.

@alamirault
Copy link
Contributor
alamirault commented Sep 27, 2023

I created PR #18934 which update documentation

@xabbuh xabbuh added the hasPR A Pull Request has already been submitted for this issue. label Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Form hasPR A Pull Request has already been submitted for this issue. Keep open
Projects
None yet
Development

No branches or pull requests

4 participants
0