1

I have a webform with a multiselect box. I want to use the prepopulate module to allow people to set the default value in the URL. The following works, but it only supports selecting one value:

/mywebform?edit[submitted][multiselect_name]=Value

Other places have suggested using URLs like the following, but that doesn't work for either one URL or multiple:

/mywebform?edit[submitted][multiselect_name][]=Value

When I pass multiple URL parameters, it just takes the last one, so Value2 is selected in the following example rather than Value and Value2:

/mywebform?edit[submitted][multiselect_name]=Value&edit[submitted][multiselect_name]=Value2

As a workaround, I could define custom GET parameters for each item in the webform using the webform module, but I was hoping to make everything consistent, and as far as I can tell, webform doesn't support GET parameters that use array notation (as per http://drupal.org/node/824606), so neither of the following works as the default in the webform module:

%get[edit][submitted][multiselect_name]
%get[edit[submitted][multiselect_name]]

Thanks for the help!

1 Answer 1

0

I have just read through the code of Prepopulate module, and it seems that as for now it doesn't support the feature you're after. The prepopulate module just assigns whatever is passed as a parameter to #value of the corresponding form element. To have multiple items selected you need to assign to #value something like this: array('Value 1', 'Value 2'); but there is no way you can pass this via parameters.

THe possible workaround is to hack the module code. Add the following code on the line #78 of the file - prepopulate.module

  if($form['#type'] == 'select' && $form['#multiple'] == TRUE) {
    $requestslice = explode(',', $requestslice);
  }

just before this line:

  $form['#value'] = $requestslice;

This change will allow you to pass multiple values as a comma separated list, for example:

  mywebform?edit[submitted][multiselect_name]=Value1,Value2

I have just created a patch for for the prepopulate module that implements this thing, you can find it here:

http://drupal.org/node/1468024

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.