I'd like to be able to capture the page a user was on when they clicked the Contact form I created with webform and include it as a hidden field. As is, the referer always says the webform itself.

Is this possible, or am I asking for a new feature?


ullgren’s picture

If you are running on a Apache webserver you can add a hidden field with the value $_SERVER["HTTP_REFERER"].
Other webservers might not support this environment variable since it not strictly a CGI 1.1 requirement.
Also if I remember correctly this taken from the browsers request so I might be forged by a bot or even left out depending on the browser implementation/security setting in the browser.

eliza411’s picture

Thanks for that suggestion. I tried it, and I apologize if I'm being dense, but I can't make it work.

When I create a hidden field, as you suggest, with the value $_SERVER["HTTP_REFERER"], all it passes to the results is the literal string $_SERVER["HTTP_REFERER"] I must be missing something.

When I create a variable on the webform itself and assign it a value $_SERVER["HTTP_REFERER"] I can echo the value I want, but I don't know how to pass it to the webform results. I put the following in the Description field:

 $referer = $_SERVER["HTTP_REFERER"];
echo $referer;

and I see the URL I want. I try to create a hidden field with the value $referer, and I just get the literal $referer.

I don't mind that the referrer can be forged or might be missing. With sitewide forms our users will often assume you know what they're looking at when they write their message, but we can't figure out what they mean unless we know where they were. On the pre-drupal site, just passing that value made it so much easier to respond to their comments and requests.

eliza411’s picture

I will try upgrading to the latest version of webform and see if that makes a difference.

I've been using // $Id: webform.module,v 2006/07/14 19:25:26 ullgren Exp

eliza411’s picture

Nope, upgrading didn't change the behavior.

quicksketch’s picture

Put the following in as the default value for a hidden input.

ullgren’s picture

Category: feature » support
Status: Active » Closed (fixed)

Yes sorry about that, it should be just as quicksketch wrote.

ullgren’s picture

Category: support » bug
Status: Closed (fixed) » Active

Just tried this my self and it seems to be a bug somewhere.

I keep getting the URL to the node itself in the referrer field even if the filed has an other value when viewing the HTML source of the rendered form.

eliza411’s picture

Yeah, the %server[HTTP_REFERER] was the first thing I tried and an obvious choice, but when it didn't do what I expected, I thought perhaps there was some other intention with that field.

Sorry I didn't file it as a bug report in the first place.

quicksketch’s picture

Status: Active » Fixed

This works correctly now in 5.x version. I'm no longer supporting 4.7. I'd advise an upgrade now that every module that will be ported to 5 has already been ported. With D6 on the horizon, it doesn't make sense to be supporting 3 branches.

Anonymous’s picture

Status: Fixed » Closed (fixed)
Valeratal’s picture

How capture the actual title of node - referer ?