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

Issue fork webform-3213155

Command icon 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

skounis created an issue. See original summary.

skounis’s picture

jrockowitz’s picture

Thanks 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...

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new1.64 KB

Similar patch but checking for 0/"0" and adding a little extra test coverage.

jrockowitz’s picture

Assigned: skounis » Unassigned
paulocs’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new31.92 KB
new32.05 KB
new31.86 KB
new31.85 KB

Looks good.
I also tested with different elements and it seems they have the correct behavior.
Attaching screenshots to confirm after and before apply patch.

  • jrockowitz authored c654519 on 8.x-5.x
    Issue #3213155 by skounis, jrockowitz, paulocs: RemotePostWebformHandler...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz authored c654519 on 6.x
    Issue #3213155 by skounis, jrockowitz, paulocs: RemotePostWebformHandler...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

skounis’s picture

I confirm, it works.