Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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
xabbuh commentedOct 12, 2016
Looks like not all tests are passing. |
7f6a42c tob56bf05CompareThis ensures that a form is always considered submitted even if itcontains only checkboxes which all haven't been checked by the user.
backbone87 commentedOct 13, 2016
The hidden input should not be added for expanded multiple choice types |
dmaicher commentedOct 13, 2016
| {%-blockcheckbox_widget -%} | ||
| <inputtype="checkbox" {{block('widget_attributes') }}{%ifvalueisdefined %}value="{{value }}"{%endif %}{%ifchecked %}checked="checked"{%endif %} /> | ||
| <inputtype="hidden"name="{{full_name }}" /><inputtype="checkbox" {{block('widget_attributes') }}{%ifvalueisdefined %}value="{{value }}"{%endif %}{%ifchecked %}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.
xabbuh commentedOct 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 commentedOct 13, 2016
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: |
ro0NL commentedOct 13, 2016
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) |
HeahDude commentedDec 3, 2016
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.