Skip to content

[Form] render hidden empty inputs for checkboxes #20210

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 1 commit into from

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Oct 12, 2016

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20179
License MIT
Doc PR

This ensures that a form is always considered submitted even if it contains only checkboxes which all haven't been checked by the user.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 12, 2016

Looks like not all tests are passing.

@xabbuh xabbuh force-pushed the issue-20179 branch 2 times, most recently from 7f6a42c to b56bf05 Compare October 12, 2016 20:15
This ensures that a form is always considered submitted even if it
contains only checkboxes which all haven't been checked by the user.
@backbone87
Copy link
Contributor

The hidden input should not be added for expanded multiple choice types

@dmaicher
Copy link
Contributor

@xabbuh I think this will also fix my issue then that I reported a while back: #14938

👍

@@ -85,7 +85,7 @@
{%- endblock choice_widget_options -%}

{%- block checkbox_widget -%}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<input type="hidden" name="{{ full_name }}" /><input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
Copy link
Contributor

@dmaicher dmaicher Oct 13, 2016

Choose a reason for hiding this comment

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

just to understand: this will render two input fields with the same name then, right? So if the checkbox is ticked then the browser will send its value as it's a successor in the DOM?

Or will it send both? like name=&name=checkbox_value

Copy link
Member Author

Choose a reason for hiding this comment

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

It will send both.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 13, 2016

@backbone87 You are right. Sending the hidden field there too would lead to wrong data. However, this also means that we would not be able to fix the underlying issue in all cases. Question is should we still follow this approach to solve at least some of them?

ping @symfony/deciders

@backbone87
Copy link
Contributor

i dont even know how to solve the case with extended multiple choice, maybe one hidden input with the "non-array"-name will work, to produce POST data like this: NAME=&NAME[]=VALUE1&NAME[]=VALUE2, but i dont know what php does with that when parsed

@ro0NL
Copy link
Contributor

ro0NL commented Oct 13, 2016

@backbone87
Copy link
Contributor

backbone87 commented Oct 13, 2016

another approach to this (which is also used within Contao, though for a different purpose) could be a separate POST variable containing submitted fields.

<input type="hidden" name="_submitted[]" value="some.field" />

this would then be handled within the RequestHandler

$data = $_POST[$name];
foreach($_POST['_submitted'] as $path) {
  $propertyAccessor->setValue($data, $path, null);
}

´
this is kind of recreating the full structure of the forms mapping array with elements that cannot be represented with application/www-url-form-encoded (however a POST with application/json, can represent these, thats why the RequestHandler for application/www-url-form-encoded is responsible for "sanitizing" the form mapping array)

the benefit of this is the full transparency for any form type, because the root cause of this problem is the application/www-url-form-encoded can only work with strings and arrays/maps and no other data type (like application/json)

@javiereguiluz javiereguiluz added this to the 3.3 milestone Nov 7, 2016
@HeahDude
Copy link
Contributor

HeahDude commented Dec 3, 2016

I think we can close here in favor of #17771.

@xabbuh
Copy link
Member Author

xabbuh commented Dec 3, 2016

Closing in favour of #17771.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants