I am using conditional recipients in my web form with a key-value input. I would like to populate the email subject field with the VALUE from the this component. Right now if I select this component, it adds the email address as the subject line. My key-value formatting is like this:
email@email.com|Subject Value

Is there a way to do this?

Thanks,
Maria

Comments

mariagwyn’s picture

Any way to do this?
m

quicksketch’s picture

No, this currently is not possible in an easy way. I believe you're able to use some addition submission code to set the subject but I haven't been able to look into it.

guz’s picture

If you "print_r($form_values)" from the additional processing section and submit the form, do you see both the key/value (email@email.com|subject) in the array? If so, just pull that value, split at the pipe (ie: explode('|',$form_values['submitted'][1]);) and re-assign the piece you want to use.

whitingx’s picture

I'm having the same problem, I'd like the value and not the email address to add to the form. Using

print_r($form_values)

shows only the key and not the value.

whitingx’s picture

Just in case this is useful for others.

I got round this by using conditional PHP (http://uk3.php.net/manual/en/control-structures.if.php) to echo the required value from the key it was returning.

If there is a cleaner way to do this I'd still appreciate hearing it.

Thanks.

uberhacker’s picture

Add the following to template.php:

/**
 * Override theme_webform_mail_headers in /sites/all/modules/webform/webform.module
 * Needed to add display value of email subject select control
 */
function [your theme here]_webform_mail_headers($form_values, $node, $sid, $cid) {
  // Get email subject component id
  $eid = $form_values['details']['email_subject'];
  if ($eid != "") {
    // Convert submitted 'safe' values to un-edited, original form.
    $components = $node->webform['components'];
    // Get array of select control values (keys) and descriptions (values)
    $options = _webform_select_options($components[$eid]['extra']['items']);
    // Get submitted display value of select control
    $subject = $options[$form_values['submitted'][$eid]];
    // Add subject to headers array
    $headers = array(
      'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')',
      'Subject' => $subject,
    );
  }
  else {
    $headers = array(
      'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')',
    );
  }
  watchdog('Webform', 'theme_webform_mail_headers has been called');
  return $headers;
}
quicksketch’s picture

Status: Active » Closed (fixed)

Thanks for the tip uberhacker! Closing after lack of activity.