2

I've created a webform in Drupal 7 with a component drop-down list. I selected 'multiple' for multiple selections. Now, I need to unselect 'multiple' giving users just one choice of the drop-down list.

Now, when viewing the submission data, the past data w/ multiple choices only show the topmost choice. How can I have the past data show the multiple choices despite I'm allowing only one choice in the component?

2
  • Depends on if the webform submissions in the database has been updated, if they have, then it's not possible.
    – user72672
    Commented Nov 14, 2019 at 20:39
  • 1
    For the component, if I switch back to 'multiple', the data chosen reappears in the submission view. So..., the data is still there. When 'multiple' is turned off, it just shows the 'top' choice, only one.
    – marklame1
    Commented Nov 14, 2019 at 20:50

2 Answers 2

1

You can keep the field set to single choice, and use hook_webform_submission_render_alter() to display the values as if it was still a multi-select field.

You can use the hook in a module or the template.php of a theme. If you are thinking about implementing it in a theme, keep in mind that the Webform Results view is displayed through the Administration theme. So, the hook must be implemented in the default administration theme for it to work in that view. By implementing it in a module, you shouldn't have to worry about which theme the submission results are being shown.

You will need the nid for the webform, and the form Key for the select field. The nid is in the url of the webform's edit page. The form key can be seen in the webform's Form componentspage.

The following code is implemented in the "my_module" module, for a webform with a nid of "100", and a field with the form key "my_select_field".

/**
 * Implements hook_webform_submission_render_alter().
 */
function my_module_webform_submission_render_alter(&$renderable) {
  if ($renderable['#node']->nid == '100' && isset($renderable['my_select_field'])) {
    $renderable['my_select_field']['#multiple'] = 1;
  }
}

The isset($renderable['my_select_field']) in the if statement may seem redundant, but it's there to prevent an exception if someone changes the form key for the field.

1
  • Excellent solution, we'll give it a try...
    – marklame1
    Commented Nov 20, 2019 at 20:55
0

You could instead create a new component for the single choice option, and disable the multi-option one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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