I was unable to get the opt-in working as a checkbox. It would always opt the user out, even when the checkbox was checked. Additionally it would throw a warning about not sending an array or object to array_key_exists().

The following code is very crude, but did fix the problem.

function webform2sugar_flatten_form($values){

        include_once(drupal_get_path('module', 'webform2sugar') . "/webform2sugar_fields.inc");

        $descriptions = '';
        $addresses='';
        $opt_in = 0;
        foreach($values as $key => $value){

                if ($key == 'email_opt_in' && !empty($value)) {
                   $data .= '&' . $key.'=yes';
                   $opt_in=1;
                   continue;
                }

                if ($key == 'email_opt_out' && $opt_in) {
                   continue;
                }

                if (!is_array($webform2sugar_available_fields)) {
                   continue;
                }                                           

CommentFileSizeAuthor
#1 webform2sugar-650900.patch5.86 KBrurri

Comments

rurri’s picture

StatusFileSize
new5.86 KB

The attached patch takes care of this issue. It makes the following changes:

1) Searches the entire [submitted] hierarchy to determine if an opt_out hidden field needs to be added. This is necessary in order to take care of cases where the opt-in box is inside of a field set.

2) Creates a special case for email_opt_out so that it is ignored if there is already an email_opt_in.

3) Handles arrays as possible values for a webform2sugar_available field. It combines these down. This is necessary because checkboxes come in as arrays. The recursive flattening should not be done on an available_field because the field key would be lost. instead the values of the array only should be flattened.

------
Note this patch also contains changes for issue #511466. So this patch would fix both #511466 and this issue #650900

robbertnl’s picture

Status: Active » Needs review
rurri’s picture

Status: Needs review » Fixed

This is now checked into the dev branch

Status: Fixed » Closed (fixed)

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