Problem/Motivation
RemotePostWebformHandler gives the option to post the data as JSON and also cast them. If we choose to do so Checkboxes are casted to booleans.
Very early in the getRequestData() method there is a check which ignores empty elements:
...
foreach ($data as $element_key => $element_value) {
if (empty($element_value)) {
continue;
}
...
This works in the most of the cases and ignores the empty values including the 0.
In the case of a checkbox though, 0 is not and empty value and should not be ignored. If we do so 0 will properly be casted to false
Steps to reproduce
1. Create a for with a checkbox
2. Attach the RemotePostWebformHandler
3. Set set the submission method to POSTand enable Cast posted element value and custom data
The try to submit the form and monitor the posted JSON. The checkbox value is posted as true when selected and 0 when not.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | checkboxUnchecked-beforePatch.png | 31.85 KB | paulocs |
| #7 | checkboxChecked-beforePatch.png | 31.86 KB | paulocs |
| #7 | checkboxUnchecked-afterPatch.png | 32.05 KB | paulocs |
| #7 | checkboxChecked-AfterPatch.png | 31.92 KB | paulocs |
| #5 | 3213155-5.patch | 1.64 KB | jrockowitz |
Issue fork webform-3213155
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
skounis commentedComment #4
jrockowitz commentedThanks for providing the initial patch.
Can you please provide a webform that can be used to replicate the issue?
We might have to check if the string is === "0".
@see https://stackoverflow.com/questions/732979/php-whats-an-alternative-to-e...
Comment #5
jrockowitz commentedSimilar patch but checking for 0/"0" and adding a little extra test coverage.
Comment #6
jrockowitz commentedComment #7
paulocsLooks good.
I also tested with different elements and it seems they have the correct behavior.
Attaching screenshots to confirm after and before apply patch.
Comment #9
jrockowitz commentedComment #12
skounis commentedI confirm, it works.