This error occurs when webform uses "select_or_other" feature.
Steps to reproduce:

  1. Create multi-page webform (at least 3 pages).
  2. Use mixture of select components on each webform page, some with select_or_other some without it.
  3. Now fill form's page 1 and page 2.
  4. On page 3 click "< Previous Page".
  5. The error occurs.

Now, although the error message relates to select.inc from webform module, the issue seems to occur only when select_or_other is used. This is the function from select.inc

function _webform_submit_select($component, $value) {
  // Build a list of all valid keys expected to be submitted.
  $options = _webform_select_options($component, TRUE);
  
  $return = NULL;
  if (is_array($value)) {
    $return = array();
    foreach ($value as $key => $option_value) {
      // Handle options that are specified options.
      if ($option_value !== '' && isset($options[$option_value])) { // <==== This is the line where error is thrown
        // Checkboxes submit a value of FALSE when unchecked. A checkbox with
        // a value of '0' is valid, so we can't use empty() here.
        if ($option_value === FALSE && !$component['extra']['aslist'] && $component['extra']['multiple']) {
          unset($value[$option_value]);
        }
        else {
          $return[] = $option_value;
        }
      }
      // Handle options that are added through the "other" field. Specifically
      // exclude the "select_or_other" value, which is added by the select list.
      elseif ($component['extra']['other_option'] && module_exists('select_or_other') && $option_value != 'select_or_other') {
        $return[] = $option_value;
      }
    }
  }
  elseif (is_string($value)) {
    $return = $value;
  }

  return $return;
}

I tried to do some debugging and it seems that when I use select_or_other module one of $value array elements is changed from string to array of strings. On line 510 webform expects that $option_value to be a string hence the error.

I tried to fix that but I'm not familiar with webform API and got totally lost.

Aside from error on line 510 of select.inc, when I click "< Previous Page" the values from previous selection are not checked by default, but instead "Other" field is active and all values, comma separated, are put there.

Comments

alan d.’s picture

Marked #1338308: Webform checkboxes & other and Save draft conflict as a duplicate.

Issue also involves the Save draft submit action and maybe related (or a separate issue) the edit submission form is also broken for me using Select (or other) 6.x-2.9 (2011-Oct-24) and Webform 6.x-3.14 (2011-Aug-31)

siliconmind’s picture

Can anyone at least confirm if this is really a webform issue? Or should this be addressed by maintainer of "select_or_other" module?

quicksketch’s picture

This will almost certainly need to be fixed here in the Webform queue.

quicksketch’s picture

Title: Illegal offset type in isset or empty in select.inc on line 510 » Illegal offset type in isset or empty in select.inc when using Select or Other on multipage forms
Priority: Major » Normal

Updating title to be more specific.

siliconmind’s picture

Priority: Normal » Major

But why do you changed the priority from major to normal? This issue perfectly matches "Priority: major" description: http://drupal.org/node/45111 The bug makes module unusable.

vernond’s picture

Priority: Major » Normal

The Webform module itself remains usable without the additional functionality of Select or other

siliconmind’s picture

This is starting to look like "wont fix" issue :/

The Webform module itself remains usable without the additional functionality of Select or other

I don't get it why Select or other is a separate module if it requires dedicated webform code anyway? Will this be fixed? Or should I forget about "Select or other" and recreate all my webforms and remove "Other..." fields?

quicksketch’s picture

I have every intention of fixing it, but it doesn't really matter whether you mark it "major" or "normal", it's what kind of priority the maintainers give the issue. We use the priority field to rate them on how important we find the issue to be in comparison to other issues in queue. End-users are always rating them how important the issue is to them personally.

4108 sites have Select or Other installed, 162621 have Webform installed. That means at most this affects 2.5% of users, and only on multipage forms that use select or other. Independently, both multipage forms and select or other work fine, so we're looking at probably around 1% of sites affected.

This issue is still important and we'll fix it eventually, just because it's relatively "normal" importance doesn't mean it won't get fixed.

lucuhb’s picture

Same problem with webform 6.x-3.15 and select_or_other 6.x-2.9 or 6.x-2.8, when click on "previous page" or "save draft" button.
It seems to be solved when :
- no integer are used as key for select options
- I add these lines in _webform_submit_select function

 @@ -507,7 +507,10 @@ function _webform_submit_select($component, $value) {
     $return = array();
     foreach ($value as $key => $option_value) {
       // Handle options that are specified options.
-      if ($option_value !== '' && isset($options[$option_value])) {
+       if (is_array($option_value)){
+        $option_value=current($option_value);
+       }
+       if ($option_value !== '' && isset($options[$option_value])) {
 
Jorrit’s picture

I have solved this bug with the following patch. I have tested it with both dropdown and checkboxes elements that have the select or other option. It seems to work.

Index: select.inc
===================================================================
--- select.inc
+++ select.inc
@@ -499,6 +499,18 @@
  * Convert FAPI 0/1 values into something saveable.
  */
 function _webform_submit_select($component, $value) {
+  $selectorother = $component['extra']['other_option'] && module_exists('select_or_other');
+  if ($selectorother && is_array($value) && count($value) == 2 && isset($value['select'])) {
+    if (is_array($value['select']) && isset($value['select']['select_or_other'])) {
+      unset($value['select']['select_or_other']);
+      $value['select'][] = $value['other'];
+    }
+    elseif ($value['select'] == 'select_or_other') {
+      $value['select'] = $value['other'];
+    }
+    $value = $value['select'];
+  }
+
   // Build a list of all valid keys expected to be submitted.
   $options = _webform_select_options($component, TRUE);
 
LittleRedHen’s picture

Your patch works for me as well, Jorrit!

I had an alternate fix in an older version of the select.inc file, but your is neater, and much easier to merge with the latest update.

alan d.’s picture

Version: 6.x-3.14 » 7.x-4.x-dev
Status: Active » Needs review

Bumping to active version, kinda surprised that I found this one again :(

rgarand’s picture

I'm seeing this as well; the actual error is an SQL error that follows the illegal offset warning:

PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1: INSERT INTO {webform_submitted_data} (nid, sid, cid, no, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4_0, :db_insert_placeholder_4_1, :db_insert_placeholder_4_2, :db_insert_placeholder_4_3, :db_insert_placeholder_4_4, :db_insert_placeholder_4_6, :db_insert_placeholder_4_select_or_other)

It appears that using the "previous" button skips the validation on the form. The select or other module relies on the validation function to fix the structure of the submitted values. When this doesn't run, webform stores a nested array as the value and ends up with an invalid query. The fix in #10 resolves the error and appears to save the values correctly when added to webform 7.x-3.16.

liam morland’s picture

liam morland’s picture

liam morland’s picture

StatusFileSize
new956 bytes

This is the fix from #10 as a patch with very minor changes. It works for me.

heivoll’s picture

The patch in #16 works for me too.

barraponto’s picture

I'm not sure whether this applies, but while working on FormBuilder's #1575064: Select (or other) Integration I noticed some warnings that might have the same origin. Here's a patch that solves that, maybe we should merge the patches.

liam morland’s picture

@#18: Why do these need to be merged? They touch different parts of the code and at a glance don't appear to depend on each other.

liam morland’s picture

StatusFileSize
new956 bytes

Reroll.

alleyhector’s picture

Is there any update on this? This seems to be my problem exactly and I'm still looking for solutions either temporary or permanent. Much appreciated.

barraponto’s picture

@liam because both patches should be applied.

quicksketch’s picture

Status: Needs review » Fixed

Thanks guys. Although I think @barraponto's patch would have been better as a separate issue, I can see the value that patch is adding here. I've applied both patches and committed them to the 4.x branch.

Status: Fixed » Closed (fixed)

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

drcolossos’s picture

Version: 7.x-4.x-dev » 7.x-3.20
Status: Closed (fixed) » Patch (to be ported)

Would be nice #18 and #20 could be merged into 3.x as well since we had the issue there as well

danchadwick’s picture

Status: Patch (to be ported) » Closed (won't fix)

At this point, 7.x-3.x is receiving critical bug fixes only. Please update to 7.x-4.x.

liam morland’s picture

Version: 7.x-3.20 » 7.x-4.x-dev
Status: Closed (won't fix) » Closed (fixed)
ngocketit’s picture

The fix in #20 doesn't solve the issue when going forward back to the form step that has the 'other' field. So here is how to reproduce it:

1. Go to the step that has the 'other' field and select 'other' from, lets say a dropdown, and put some value.
2. Go to the previous step. The warning is not present anymore so the patch works.
3. From the current step, to to the next step which is where we have the 'other' field. The field will still have something like "Array xxxx" where "xxxx" is the entered value.

I modified the patch a bit and following piece of code works for me with Webform 7.x-3.x and select_or_other 7.x-2.22:

 if (module_exists('select_or_other') && $component['extra']['other_option'] && is_array($value) && count($value) == 2 && isset($value['select'])) {
    if (is_array($value['select'])) {
      if (isset($value['select']['select_or_other'])) {
        unset($value['select']['select_or_other']);
      }
      else {
        foreach ($value['select'] as $index => $val) {
          if ($val == 'select_or_other') {
            unset($value['select'][$index]);
            break;
          }
        }
      }
      $value['select'][] = $value['other'];
    }
    elseif ($value['select'] == 'select_or_other') {
      $value['select'] = $value['other'];
    }
    $value = $value['select'];
  }