Hi,
is it possible to exclude empty fields from email?
I have a lot of fields in my form - and the text-email becomes very user-unfriendly, as all empty fields are also stored in the email.
Is there a way to stop this?
I am already working with a custom email-template - but did not find out, what to include.
Regards
vistee
Comments
Comment #1
quicksketchIn your custom e-mail template, you can add a few lines to remove components that do not have any value. You'll just need to expand on the example already provided in the .tpl.php file.
In your webform-mail.tpl.php that you've copied to your theme directory change lines 38 through 43 to:
Comment #2
vistree commentedHi quicksketch,
thank you very much for this fast reply.
I tried your code out - but it does not work.
The result is the same as without the foreach-loop.
Is there something still not correct, or can it have todo with my 6.2.3-version of webforms?
Kind regards
vistree
Comment #3
vistree commentedAh yes, and I use a lot of fieldsets and also multipage-layout of my webform.
Regards
vistree
Comment #4
quicksketchRight... in which case you'll need to do multiple loops (or recursive looping) to remove all the empty values inside of fieldsets. The approach I used above would only work if you didn't use any fieldsets. Multiple pages do not make a difference though when dealing with e-mails.
Comment #5
vistree commentedAh OK,
How can I loop through the fieldset than? Is the resulting value of
the fieldset?
And can I just loop again like
I have NO idea on php. So I would be very glad to have help again.
Best regards
vistree
Comment #6
vistree commentedOk, now I tried to play a little bit with the possible values and found out, that the value of a fieldset is 'Array'.
Now I thought, that it could be quite easy to generate an additional loop. But my code still does not work:
Can anyone help me with the additional loop?
Kind regards
vistree
Comment #7
vistree commentedI still search for a solution.
Is there anyone fit in PHP and can explain how to also remove the empty fields from fieldset?
Hope for help ;-)
Thanks and regards
vistree
Comment #8
quicksketchSomething like this should be pretty close. Again, not tested.
Comment #9
vistree commentedHi quicksketch,
this works absolutly perfect!!!!
Thank you so much!!!
Last question on this: is it also possible to remove the name of the fieldset (the fieldset title) if the fieldset is empty??
Kind regards and again 1000 thanks
vistree
Comment #10
quicksketchHa! I can't believe that worked ;)
What's happening is the empty array of values is still left, even though all the values are gone. This *should* remove the empty array too.
Comment #11
vistree commentedHi, you are amazing!!! Works perfect without any modifications.
Thank you very much!!!!!!!!
No, everything is perfekt!!
Regards
vistree
Comment #12
quicksketchComment #13
ryndog commentedHey there,
I am trying to accomplish this as well (empty fields to be excluded in the form email). After editing my drupal/modules/webforms/webform-mail.tpl.php I am still getting empty fields sent in my emails. Here is what I have done:
Edited the drupal/modules/webforms/webform-mail.tpl.php file to read:
Let me know if I can provide any more information. Any help would be greatly appreviated. Thanks in advance!
Comment #14
ryndog commentedAny idea?
Comment #15
ahimsauziSubscribing
Comment #16
CubicX commentedAny help on how to do this in 6.x-3.0-beta 5?. Above methods won't work sadly enough.
Comment #17
breethink commentedSubscribing
Comment #18
iwant2fly commentedSubscribing - I get the following error when using the previously mentioned code
warning: Invalid argument supplied for foreach() in modules/webform/templates/webform-mail.tpl.php on line 29.
Comment #19
hiweed commentedSubscribing.
Just like in email, I also want to the webform displays only the non empty fields in the result (Submissions) page.
Thank you!
Comment #20
Anonymous (not verified) commentedSubscribing
Comment #21
slieps commentedI also want to remove the empty fields from the e-mail? I have a very long form with many fieldsets.
All the solutions above won't work.
Is there a solution what works with the webform module 6.x-3.4.
Thank you
Comment #22
jwinton commentedSubscribing
Comment #23
askibinski commentedThe solution above is for the 6.x-2.x branch.
The solution for the 6.x-3.x branch can be found here:
http://drupal.org/node/749360#comment-2751838
Comment #24
rajmataj commentedCan anyone suggest a working solution for Webform 6.x-3.20? Have tried the above solution in template.php:
...which does not seem to work and comment #23 refers to what has become the 7.x version.
Thanks.
Comment #25
liam morlandComment #26
danchadwick commentedThe 6.x branch is receiving critical bug fixes only.