Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DomCrawler\Form doesn't handle image inputs properly #10204

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
robbertkl opened this issue Feb 4, 2014 · 2 comments
Closed

DomCrawler\Form doesn't handle image inputs properly #10204

robbertkl opened this issue Feb 4, 2014 · 2 comments
Labels
DomCrawler Good first issue Ideal for your first contribution! (some Symfony experience may be required)

Comments

@robbertkl
Copy link
Contributor

When a DomCrawler\Form is initialized with an <input type="image" name="bar"> element, it will end up in $form->getValues() as "bar", instead of "bar.x" and "bar.y". Because of this, there is no way to set the values for the x and y coordinates and it will incorrectly miss those variables in the GET/POST data, would the form be submitted.

Ran into this issue while using fabpot/Goutte, where my submitted form did not get picked up properly by the receiving webserver, because the "imageinputname".x and "imageinputname".y were not present in the POST data.

@fabpot
Copy link
Member

fabpot commented Feb 4, 2014

Good catch, should be easy to fix. Can you work on a patch?

@robbertkl
Copy link
Contributor Author

A solution might prove to be a bit less trivial as it initially seems. The problem is that an image input (a single element) actually results in multiple variables (name.x and name.y) being submitted, unlike any other input element that I'm aware of. Because of this, it does not 'fit' nicely in the current structure.

I've just added PR #10205, which proposes a fix by adding multiple FormFields, but please let me know if you have any suggestions of a better fix.

fabpot added a commit that referenced this issue Feb 5, 2014
…bertkl)

This PR was merged into the 2.3 branch.

Discussion
----------

[DomCrawler] Fixed incorrect handling of image inputs

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10204
| License       | MIT
| Doc PR        |

A possible approach to fix #10204, but I'm open to suggestions to fix this another way, as this might not be the most 'elegant' way.

Initially, my thoughts were to create a new DomCrawler\Field\FormField subclass, especially for image inputs. However, this does not solve the problem, because such a FormField would still exist under 1 name in the FormFieldRegistry.

Instead, I've changed it to have 2 separate FormFields instead (which both reference the same input node), with different names (.x and .y) so that both values can be set separately and will both be submitted.

Commits
-------

816cf17 [DomCrawler] Fixed incorrect handling of image inputs
@fabpot fabpot closed this as completed Feb 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DomCrawler Good first issue Ideal for your first contribution! (some Symfony experience may be required)
Projects
None yet
Development

No branches or pull requests

2 participants