Including the "referred" with form submissions

Permalink
We want our contact form to include the website and/or search engine that brought the user to our site. (Not necessarily to the contact page directly, but to anywhere in our site.)

We don't want the user to enter that information. We want that to be automatically included with the form data (but hidden to the user of the website who submitted the form.)

How can I do that?

Thanks.

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi yosefgold,

What version of concrete5 are you using?

I believe you want to save the HTTP referer field included in the HTTP header of the HTTP request.

I am not sure if there is way to add this to a contact form without some custom code.

If you are using concrete5 5.7:

One idea might be to make a custom block that you place in a global area. The block gets the HTTP referer using $_SERVER['HTTP_REFERER']. The first HTTP referer is saved to a "referer" cookie using the cookie service. In your contact form, you could use JavaScript to read the value of the referer cookie and add it to a hidden field in your contact form.

cookie service -http://concrete5.org/api/class-Concrete.Core.Cookie.CookieJar.html...

I believe this should work, but it is clunky and I know there is a more elegant way to do it.
mnakalay replied on at Permalink Reply
mnakalay
@MrKDilkington idea is a good one wit one little modification needed in my opinion.

There is one scenario in which the cookie saved from a block in a global area idea MIGHT not work: if the user arrives directly on the page with the form on it. The cookie will be saved but it might not be available for the form to load depending on how the page loads.

Personally I would use an event, maybe on_before_render, to save the cookie.

Frankly I have not tried it and @MrKDilkington knows what he's talking about so if he says this won't fly, I won't argue :)
MrKDilkington replied on at Permalink Reply
MrKDilkington
@mnakalay

You make an excellent point about arriving on the page with the form directly. Using on_before_render() sounds like it could deal with that scenario.

I have not tried it either.

(trust mnakalay, he is the one who knows what he is talking about, not me)
hrcv replied on at Permalink Reply
hrcv
Hello!

Did you came up with this goal achieved?
If yes, how did you make it?