Problem/Motivation
After upgrading to the last version of Webform, checkbox values return a default value in the email confirmation/notification sent to the user, regardless if a custom value is set under: Build > Elements > Edit "My-Checkbox-Field" > "Advanced" > "Return/Default Value" field.
Before the upgrade it worked as expected.
To be more clear: I have a checkbox field not selected by default. If a user select the checkbox it should return in the e-mail the value I set in the custom field under "Advanced" field configuration, in my case "Voglio ricevere la demo", but when I fill in the form for a test, in the mail I receive the value "Yes" under the field label.
Additional Info: I'm using SMTP mail to send e-mail and MailSystem has module specific configuration for webform: Webform PHP mailer both in Format and in Sender.
All the project is updated to the last current version (drupal 8.9.13, Mail System 8.X.4.3, SMTP 8.x.1.0).
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3209476-11.patch | 548 bytes | jrockowitz |
| #6 | 3209476-6.patch | 3.12 KB | jrockowitz |
| #3 | 3209476-Checkbox-doesnt-return-custom-value-in-the-email-notification-confirmation-3.patch | 845 bytes | marcusvsouza |
Comments
Comment #2
marcusvsouza commentedWorking on it!
Comment #3
marcusvsouza commentedHere's a patch to solve this problem.
Comment #5
tiikeri commentedDear Marcus, thanks a lot for taking care of this bug.
I tested the patch against the last version of Webform 6 and drupal core 8.9.14 and it seems to works well.
Still not tested against drupal 9 (where the automated test failed).
I will test it on tomorrow and get back with a feedback.
Comment #6
jrockowitz commentedI am not able to find any regressions. The #return_value support was added via #3116535: Allow checkbox element's return (raw) value to be customized.
Still, I think making it possible to display the #return_value should be easier. The attached patch adds a 'Return value' form option to all boolean elements.
This issue should also be fixed via 8.x-5.x.
Comment #7
jrockowitz commentedComment #8
jrockowitz commentedThe attached patch should work in 6.x and 8.x-5.x
Comment #10
jrockowitz commentedComment #11
jrockowitz commentedI keep looking at the code, and the #return_value support never displayed the return value unless the checkbox's format was set to 'Raw value.'
I don't think we want to change this behavior. If you want to display the #return_value, you need to set the format to 'Raw value.'
The simplest solution to change 'Raw value' to 'Raw/return value' in the element edit form.
Comment #12
marcusvsouza commentedTested, the patch applies properly and works as expected in comment #11
Comment #13
jrockowitz commentedComment #17
lindsay.wils commentedSorry to reopen an old issue, but I am seeing some odd results here.
Setting my checkbox as explained with raw value, the results are showing always as 0, which seems to be due to line 42 on BooleanBase.php
return ($element['#return_value']) ? $value : 0;
changing to
return $element['#return_value'];
and then the custom return value shows correctly on the webform submission result page.
I am using a remote post to submit this data to an external system and believe this to be the reason Im not seeing the expected results.
Could I be onto something here?
Sorry, Im not up to speed on creating patches and tests...