Skip to content
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

Cannot map "0" to a numeric or text field in a Civi form #3

Open
nc3man opened this issue Mar 30, 2021 · 5 comments
Open

Cannot map "0" to a numeric or text field in a Civi form #3

nc3man opened this issue Mar 30, 2021 · 5 comments

Comments

@nc3man
Copy link

nc3man commented Mar 30, 2021

When the number 0 (or text "0") is entered in a Caldera form, either directly in an input box, or as a value from a radio selection, 0 appears to get replaced by "null" at some point prior to running a CiviCRM Form Processor which needs this parameter. If this is an expected parameter on the Civi form processor, you get a FAIL when submitted.

I discovered this on a more complicated form, but I created a super simple example to illustrate the error. The Caldera form is named test_input_zero and is exported as test_input_zero-export.json. The Civi Form Processor that is used as a processor in test_input_zero is test_num_civi and is exported as test_num_civi.json. I zipped both exports to attach here
test_input_zero.zip. I'm also attaching a screenshot of the McRestFace Log after entering a "1" for the numeric field in test_input_zero. It is correctly passed through as input to test_num_civi processor in CiviCRM.
cf_interface_enter_1

Entering the number 0 shows that null is passed to test_num_civi and so the processor fails as also shown in the McRestFaceLog
cf_interface_enter_0

There is no issue with any other non-zero integer, including negative numbers, being passed through the interface. 0 just is interpreted as null for some reason. Is there a setting to prevent this?

@nc3man
Copy link
Author

nc3man commented Mar 30, 2021

Hunting through the code, I don't see where a zero(0) might get mapped to null. I do see that once that value is null, then the corresponding key in the params array is removed, which is why we get the message "Mandatory key(s) missing ..."
So the logic to remove the key may be at line 161 in class-formprocessor-processor.php

// Remove null values from array otherwise we might get uggly errors.
    foreach($result as $key => $val) {
      if ($val === null) {
        unset($result[$key]);
      }
    }

@nc3man
Copy link
Author

nc3man commented Mar 30, 2021

I removed the test_num_civi processor and just added the Auto Responder to verify that Caldera Forms interprets the "0" input correctly. It appears to be somehow being transformed in this plugin.

@nc3man
Copy link
Author

nc3man commented Mar 30, 2021

Just to be sure that I hadn't mangled something with learning about this plugin on our test site, on our live site I did a completely fresh install of CiviCRM extensions Action-Provider and Form-Processor, and fresh installs of Caldera Forms, Integration of CiviCRM Form Processor with Caldera Forms, Connector to CiviCRM with CiviMcRestFace so I could see the logging (set up a local connection with our local Civi). I imported the two examples zipped up here, and repeated the test. The difference was that I set the field to be short text instead of numeric on both sides. Same issue - "0" does not make it through but other characters do.
image

@nc3man nc3man changed the title Cannot map "0" number to a numeric field in a Civi form Cannot map "0" to a numeric or text field in a Civi form Mar 31, 2021
@nc3man
Copy link
Author

nc3man commented Mar 31, 2021

For a short term fix, I can just pass characters to the Civi Form and then map to 0. I don't understand how the Map Value action works. Can someone show me an example, please? I want to map "Y" to numeric 1 and "N" to numeric 0. I also want the reverse map: 1=>"Y" and 0=>"N" for retrieving defaults. I tried guessing at the correct JSON format for the mapping, but my guesses have not worked. One simple example is all I need and this would at least give us a workaround for our current application which is on a schedule to be completed soon.

@nc3man
Copy link
Author

nc3man commented Apr 3, 2021

I have a short term fix for our use case. In the Civi Form Processor, I did not make the primary inputs required and set the default to 0. So, even though a 0 on the Caldera side gets mapped to null by the Integration plugin, the default correctly sets the value to 0. I also made the variables in the Civi Form Processor of type Custom Options with values 0 & 1, labels "Yes" and "No". Screenshot is from the McRestFace log. Everything is working for our application this way, but the 0 entered in the form's "newsletter" field should still not be set to null, imo. I still would like to understand how to set the Action: Map Value to work with a JSON example.
image

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

No branches or pull requests

1 participant