I have a webform working fine and sending email with the user ID and IP address included in the email body and subject line, but if the user is anonymous, it won't print "Submitted by anonymous user", or the IP address, in either place. This code seems to be failing:

<?php if ($user->uid): ?>
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by user: %username') . ($email['html'] ? '</p>' : ''); ?>
<?php else: ?>
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by anonymous user: [%ip_address]') . ($email['html'] ? '</p>' : ''); ?>
<?php endif; ?>

All of the other custom fields print out fine in the email body.

I attached the custom file: webform-mail-19789.tpl.php (renamed webform-mail.tpl_.txt)

What's wrong? I couldn't find any configuration options governing this.

Files: 
CommentFileSizeAuthor
webform-mail-19789.tpl_.txt2.3 KBdruplicate

Comments

druplicate’s picture

I just noticed I shouldn't have included the brackets --> [%ip_address], but it didn't make any difference when I removed them.

The body has this line: "Submitted by user:" and nothing after it (unless it's a registered user). The default value for the subject line is: 'Inquiry for property ID: %get[propid] - IP Address: %ip_address'. The IP first variable always gets printed but the IP address is omitted if the user is anonymous.

quicksketch’s picture

The most likely problem is that this template isn't getting used at all. If you're not using the "Default" template in the Webform interface for editing e-mails (node/x/webform/emails), the PHP code in the template won't ever fire because Webform will use the user-specified template in the interface instead.

druplicate’s picture

That is the problem but it's a bit complicated.

On my test server I went to check it and it was set to use the custom template. I clicked the drop down box and changed it to "default" and a pop up box appeared asking for a confirmation. Then I saved the form, and voila the IP address is getting reported in the email subject line.

Then I went to do the same on the live server but it was already set to default. I tried changing it to custom but got no popup confirmation message. I saved the form and opened it again and noticed it was still stuck on "default". Now on the test server I have the same problem - I cannot get it to switch back to using the custom template, but it is using the default custom tpl.php I made, whereas the live server isn't. So the whole time I thought it was using the new template file and it wasn't.

Weird.

quicksketch’s picture

If you're using CKEditor by chance, you may be suffering from #1087926: Webform refuses to use 'default template' when template fieldset uses CKEditor.

druplicate’s picture

I'm not using CK Editor for the custom template text area - no editor at all. I use CK editor but only with WYSIWYG, in other areas. What's odd is it worked but only once. After that it seems stuck.

So my test server is stuck on using the default customized tpl.php, and my production server is stuck using the custom template.

druplicate’s picture

Version:6.x-3.11» 7.x-3.11

Just made a new webform and this time I did not specify a unique tpl.php file as I did before.

I just have "%ip_address" in the body of a hidden field that I use for the email subject.

The IP address does show up in the body of the email however, by using the default template with "Submitted by user: %username" and even though the notes say it will be blank for anonymous users, it results in: "Submitted by anonymous user: [113.53.11.111]"

If I use "%username" in the hidden field used for the email subject, it returns no value.

If I use a custom template in the email settings section, and add "%ip_address", it also returns nothing, AND the original field for %username also returns nothing. Just using the custom template selection voids the IP address token as well as the User token. For logged in users, everything works as expected and the IP address is displayed.

Something's screwed up.

druplicate’s picture

Title:email does not include anonymous user» email does not include anonymous user IP address
Version:6.x-3.9» 6.x-3.11
Category:support» bug

Wrong code version. It's 6.x-3.11

quicksketch’s picture

Version:7.x-3.11» 6.x-3.11

The IP address does show up in the body of the email however, by using the default template with "Submitted by user: %username" and even though the notes say it will be blank for anonymous users, it results in: "Submitted by anonymous user: [113.53.11.111]"

There is absolutely no way this statement is correct.

Submitted by user: %username

Could never expand to:

Submitted by anonymous user: [113.53.11.111]

How would "anonymous" get inserted before the word "user" and the IP address come afterward?

It sounds like your custom template is either still taking effect or the results are getting mixed up in your report. If you can provide steps to reproduce a problem from a clean Webform install I'll take a look at it.

druplicate’s picture

Sorry, I didn't give enough information.

webform-mail.tpl.php is in my theme directory and contains this code:

<?php if ($user->uid): ?>
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by user: %username') . ($email['html'] ? '</p>' : ''); ?>
<?php else: ?>
<?php print ($email['html'] ? '<p>' : '') . t('Submitted by anonymous user: [%ip_address]') . ($email['html'] ? '</p>' : ''); ?>
<?php endif; ?>

The above code is working fine as the IP address of the anonymous visitor gets displayed in the body of the email.

In the text component used for the email subject, I have just these tokens: IP Address: %ip_address - User: %username which displays both IP address and username for logged in users but neither for anonymous visitors. For some reason the token is failing for anonymous users when used in the text component that then gets used for the email subject.

quicksketch’s picture

Status:Active» Closed (cannot reproduce)

I'm closing this issue after a lack of activity, I'm hoping that it was fixed in subsequent releases of Webform. If the problem still exists with the latest version of Webform, please reopen.

druplicate’s picture

Now using version 3.17 and still had the problem however I just moved the server from Linode.com to Omega8.cc and the problem resolved itself. The Linode box was Ubuntu 8.04 and it did not have a firewall installed.

BTW, Omega8 blows the doors off of my simple basic caching server on Linode for speed (about doubled) and part of the reason for that is the across the board use of solid state drives. Pay for a year in advance and it's less than what I was paying on Linode ($34 VS $40). You don't get complete control of the server (limited shell) as with Linode, but in my case that's a feature as I no longer have to care about maintaining the server. You also get much less disk space, but you can host any number of sites, unlike Pantheon.

One of the reasons I switched was to avoid maintaining Ubuntu with the latest version of My SQL (to use the reverse node reference module that requires MySQL 5.1) but because I'm using D6, I also needed PHP 5.2 and the two don't coexist in any standard supported Linux package that I'm aware of, so I just let Omega worry about that stuff now. Hooray! Omega8 uses several advanced caching mechanisms and Nginx instead of Apache, and uses Aegir to manage your sites. Excellent support too!