4

I'm trying to figure out how to set the default values of the Webform Results > Download > Included Export Components Field to exclude certain fields.

The webform module defaults to a state for that field in which all the webform's fields are checked. They can be manually unchecked before each download but we've run into a business requirement by which we would require 3 fields (IP Address, Draft, and UID) to be unchecked on the page load.

I've looked through the configuration pages for the webform module and for the specific webform node and have come up empty handed. I've considered writing an additional module which will override the module which sets the checkboxes. Before I went that route though, I was wondering if anyone has dealt with this requirement before and/or can share some insight/point me in the right direction.

Thanks!

1 Answer 1

3

I remember having to do that once, and though I looked at how the values were initially set, I still ended up using hook_form_alter to change them. I don't remember why exactly, but presumably due to fact I couldn't reach them as easily.

Just use a hook_form_alter in a custom module to get to the form, and unset the defaults you don't want.

This should pretty much do it in a hook_form_alter or hook_form_ID_alter ( example is for hook_form_alter ) :

if ($form_id == 'webform_results_download_form') {
  /**
  * default ( and named ) components are :
  * - serial: Submission nr
  * - sid: Submission ID
  * - time: Time
  * - draft: Draft
  * - ip_address: IP Address
  * - uid: User ID
  * - username: User Name
  */
  $excludes = array('serial', 'sid');

  foreach ($form['components']['#default_value'] as $cid => $component) {
    if (in_array($component, $excludes)) {
      unset($form['components']['#default_value'][$cid]);
    }
  }
}

This will uncheck both the Submission Nr & Submission ID checkbox. Adjust the $excludes array accordingly to your needs

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.