Hello,

i use great plugin named Webform to make form and send it to email. Is it possible to filter and send to the email ONLY fields with some input? So, empty fields, won't be sent to the email.

Thanks for any advice, Gamma

Comments

iwant2fly’s picture

I am also looking for an answer to this question.

maxferrario’s picture

I was able to hide the empty fields only by theming the confirmation email.
See THEMING.txt file in module folder: you need a little of PHP knowledge, though, as you have to modify email templates

iwant2fly’s picture

Right exactly what I don't have. I can copy and paste code and marginally understand what I am doing. Anyone kind enough to give me some step by step guidance? The theming.txt file really doesn't provide much information. It basically says you can theme the e-mail. This I know, but how? Sorry I am letting my frustration show. There are a ton of post on this with people saying they figured it out without putting detailed directions as to how.

maxferrario’s picture

I will send you an example tomorrow: the files I created are on the server in my office.

iwant2fly’s picture

You are awesome. Thank you so much.

maxferrario’s picture

Here is my webform-mail-ID.tpl.php
I hope the comments I included will let you understand how to modify the output: if something is still unclear feel free to ask


<?php
// $Id: webform-mail.tpl.php,v 1.1.2.5 2009/11/06 00:59:47 quicksketch Exp $


  // uncomment the line below can be usefull to see what is passed within $form_values['submitted_tree']  
  //print_r($form_values);
	
  // $my_form_values contains all data to be passed to the theme function: I will manipulate this hash
  $my_form_values = $form_values['submitted_tree'];

  // message printed before the fields list
  $intestazione = 'Gentile ' . $my_form_values['dati_anagrafici']['nome'] . ' ' . $my_form_values['dati_anagrafici']['cognome'] . ',';
  $intestazione .= "\r\n";
  $intestazione .= 'grazie per aver scelto di essere protagonista accanto alle nostre equipe sul terreno ogni giorno dell\'anno.';
  $intestazione .= "\r\n\r\n";
  print t($intestazione);

  // output manipulation
	
  // example 1: put address information on one line
  // I create one string and assign it to the "right" filed (the one with the right label)
  // to suppress the output of the other fields I unset them 
  $indirizzo = '';
  $indirizzo .= $my_form_values['dati_anagrafici']['indirizzo'] . ' ' . $my_form_values['dati_anagrafici']['numero_civico'];
  $indirizzo .= ', ' . $my_form_values['dati_anagrafici']['cap'] . ' ' . $my_form_values['dati_anagrafici']['citt'];
  $indirizzo .= ' (' . $my_form_values['dati_anagrafici']['provincia'] . ')';
  $my_form_values['dati_anagrafici']['dug'] = $indirizzo;
  unset($my_form_values['dati_anagrafici']['indirizzo']);
  unset($my_form_values['dati_anagrafici']['numero_civico']);
  unset($my_form_values['dati_anagrafici']['citt']);
  unset($my_form_values['dati_anagrafici']['provincia']);
  unset($my_form_values['dati_anagrafici']['cap']);
  
  // if a field is empty I unset it to suppress its output 
  if ($my_form_values['dati_anagrafici']['gia_donatore']==0) {
    unset($my_form_values['dati_anagrafici']['codice_donatore']);
  }
	
	
  // Print out all the Webform fields. This is purposely a theme function call
  // so that you may remove items from the submitted tree if you so choose.
  print theme('webform_mail_fields', 0, $my_form_values, $node);
	
  // this message will be printed below the field list
  $chiusura = "\r\n\r\n";
  $chiusura .= 'Medici Senza Frontiere sta procedendo all\'attivazione della tua donazione regolare: il processo sarà completato in circa 15 giorni.';
  $chiusura .= "\r\n";
  //
  print t($chiusura);
?>

iwant2fly’s picture

Thanks. I will try this shortly. I looks exactly like what I need.

iwant2fly’s picture

The code seems to describe exactly what I want it to do, but I cant get it to work. Could it be that I am using the latest version of Webform 6.x-3.2? The theming seems to have changes some with this newest version, but I don't know enough to know what I need to do. I am using multiple field-sets so I know that complicates things somewhat.

Just to restate what I am trying to do for clarification and for those skipping the first part of the thread. I want to edit the email sent by webform to not include the fields that are left blank. My form has a large number of fields (70+) of which a large majority are left blank.

maxferrario’s picture

Unfortunately theming webform is very different in version 6.2 and version 6.3, so my example is not valid for the webform version you use.
Read THEMING.txt file in webform folder and take a look to templates/webform-mail.tpl.php to see how to adapt my examples to the new environment.
I will study them ASAP as I would like to migrate all my webforms (and customizations) to the last version, but cannot tell you anything at the moment.