Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Looks like not all tests are passing. |
7f6a42c
tob56bf05
CompareThis ensures that a form is always considered submitted even if itcontains only checkboxes which all haven't been checked by the user.
The hidden input should not be added for expanded multiple choice types |
@@ -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 %} /> |
There was a problem hiding this comment.
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? likename=&name=checkbox_value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It will send both.
@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 |
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: |
For the record, we use this approach:http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked#answer-35689714 |
backbone87 commentedOct 13, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
another approach to this (which is also used within Contao, though for a different purpose) could be a separate POST variable containing submitted fields.
this would then be handled within the RequestHandler $data =$_POST[$name];foreach($_POST['_submitted']as$path) {$propertyAccessor->setValue($data,$path,null);} ´ 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) |
I think we can close here in favor of#17771. |
xabbuh commentedDec 3, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Closing in favour of#17771. |
This ensures that a form is always considered submitted even if it contains only checkboxes which all haven't been checked by the user.