Problem/Motivation

I am trying to put people into certain groups if they fill out certain forms on my site. I figured I could do this if I created a hidden field and set it to a certain values that anyone who fills out the form and opts into my newsletter will be added to that group. However if I use a hidden field component or if I set a component to private, the form throws an error upon submission.

Notice: Undefined index: items in webform_mailchimp_webform_submission_insert() (line 117 of webform_mailchimp/webform_mailchimp.module).
Notice: Undefined offset: 1 in webform_mailchimp_webform_submission_insert() (line 121 of webform_mailchimp/webform_mailchimp.module).
Notice: Undefined index: Wedding Contact Form in webform_mailchimp_webform_submission_insert() (line 124 of webform_mailchimp/webform_mailchimp.module).

However if I remove the "private" selection and expose the component, then the form submits correctly, I get no errors and the user is added to the correct group. Am I doing something incorrectly? Is there a better way to add someone to a group upon form submission?

Proposed resolution

Support single value components as well.

Remaining tasks

Review and Test Patch.

User interface changes

API changes

Original report by @waltercat

CommentFileSizeAuthor
#4 can_t_pass_interest-2177063-4.patch2.06 KBjoelpittet
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

teamninja’s picture

I too have the same issue. We are passing some hard coded values in multiple input fields that we do not want the user to see when they are filling out the form.

adam_b’s picture

The only way I've found to pass hidden values successfully is:

  • make another form component with select options
  • set the defaults to the ones you want, and make it mandatory
  • do *not* set it to Private (it'll only work for admin users)
  • use CSS {display: none} to hide the component from the end user

It's a bit of a hack, but it seems to work. I agree, it would be nice if the Hidden form component worked in this case.

joelpittet’s picture

Category: Support request » Feature request

Yes, I have this issue true:

Seems to be related to this snippet of code:

   if (!empty($groupfields_key_array) && is_array($groupfields_key_array)) {
      foreach ($node->webform['components'] as $key => $field) {
        if (!empty($groupfields_key_array[$field['form_key']])) {
          // We are dealing with checkboxes, dropdowns and have received the id
          // instead of the raw value. So we need to extract the value and send
          // that instead.
          $choices = explode("\n", $field['extra']['items']);
          $sorted_choices = array();
          foreach ($choices as $choice_key => $choice_val) {
            $id_name = explode('|', trim($choice_val));
            $sorted_choices[$id_name[0]] = $id_name[1];
          }
          foreach ($submission->data[$key] as $filled_out_value) {
            $groupfields_replacements[$groupfields_key_array[$field['form_key']]][] = str_replace(",", "\,", $sorted_choices[$filled_out_value]);
          }
        }
      }
      foreach ($groupfields_replacements as $groupname => $values_array) {
        $mergefields_replacements['groupings'][] = array(
          'name' => $groupname,
          'groups' => $values_array,
        );
      }
    }


joelpittet’s picture

Status: Active » Needs review
FileSize
2.06 KB

Can someone give this patch a try?

It should do both hidden and select/options.

joelpittet’s picture

+++ b/webform_mailchimp.module
@@ -115,17 +115,22 @@ function webform_mailchimp_webform_submission_insert($node, $submission) {
+              $groupfields_replacements[$groupfields_key_array[$field['form_key']]][] = str_replace(",", "\,", $sorted_choices[$filled_out_value]);

This isn't part of the patch, but it looks suspicious str_replace(",", "\," ..., Anybody want to also confirm that that still works with webform 4.x and mailchimp module 3.x?

joelpittet’s picture

Title: Can't Pass Interest Value if Field is Hidden » Can't Pass Interest/Group Value if Field is Hidden or single value field
Issue summary: View changes
CatherineOmega’s picture

Joel, I haven't been able to get that to work, I'm afraid. I'm wondering if it's partly due to the fact that I'm populating the hidden field with JavaScript, or if I'm missing something about how Mailchimp assigns names to groups?

joelpittet’s picture

It may be due to the js population @CatherineOmega, but you'd need to do a simple test case with the FAPI to see if the values get posted after JS populates them.

Or if you have an IDE like PHPStorm or Eclipse, set a breakpoint in the submit handler and ensure your JS comes across.

CatherineOmega’s picture

Okay, nope. It appears that interest groups don't work at all in Webform 4.x and Mailchimp module 3.x, at least when it comes to webform_mailchimp. I'm continuing further testing to see if it's because of Mailchimp module or what.