homepage Welcome to WebmasterWorld Guest from 54.196.225.45
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
referrer URL in form?
bellabia




msg:3347919
 7:54 pm on May 23, 2007 (gmt 0)

Hello everyone!
I am in desperate need of some help on an issue I'm having with a site I'm building. Basically, I'd like to know if it's possible to get my form to submit the referring URL (previous page info) or something like that. I'll explain:

I'm designing a site for a travel company. They already have a booking engine but they want a section on the site where they could post in-house products (each product on it's own full page). There is NO CMS for this, I'm building them in plain HTML. So, if a client is interested in one of the packages, they would click the "Reserve now" button and are taken to the "reservation" form. My problem is that I don't want to build an individual form for each page, I'd rather have one central form that somehow catches or records the referring URL (or package info) so that when the form submits, we will know which package they want to reserve.

Can anyone help me?

 

colandy




msg:3348467
 9:42 am on May 24, 2007 (gmt 0)

Using PHP you can use the $_SERVER['HTTP_REFERER'] variable, however I believe that cetain web servers don't supply this. I would suggest that any web servers worth their salt will supply this variable.

colandy




msg:3348470
 9:44 am on May 24, 2007 (gmt 0)

Sorry, Just read the second Para, don't think this is possible without PHP, don't know of any HTML or Javascript that will give you this info.

Dabrowski




msg:3348526
 11:10 am on May 24, 2007 (gmt 0)

I thought the location object had the referer but just looked it up and it hasn't. The only way (easiest) to do this would be to use that tiny bit of PHP.

I wrote a web stats package which uses the referer and most of the time it works, however sometimes it's blank. Doesn't seem to matter what OS or what Browser, but I think some firewalls can block it. It's about 96% reliable I think.

colandy




msg:3348608
 12:56 pm on May 24, 2007 (gmt 0)

The browser I know that doesn't is Abyss, Apache does and IIS does.

Dabrowski




msg:3348630
 1:22 pm on May 24, 2007 (gmt 0)

You mean servers. With my webstats software I made it record HTTP_USER_AGENT if there was no referer string, absolutely no correlation.

Sometimes the same user (can tell from cookie ID) would appear with no referrer, then it would magically appear after they'd looked at a few pages.

bellabia




msg:3348968
 6:35 pm on May 24, 2007 (gmt 0)

Hi guys, thanks for getting back to me!

If I were to do this with PHP, would that work WITHOUT me having to change my HTML pages? I just want the form to submit a hidden field which records the referrer URL (previous page they were on). Can a PHP form do that? And if so, does anyone know of any ready-made scripts available (sorry,I'm not a coder - just a designer) =)

Dabrowski




msg:3349038
 7:55 pm on May 24, 2007 (gmt 0)

Yes, PHP is inline with your HTML which means, assuming your server supports PHP, that you can just add 1 line into your form page.

I don't do PHP either though, colandy can you provide the complete code snippet?

Dabrowski




msg:3349039
 7:57 pm on May 24, 2007 (gmt 0)

Let me have a go, see if I've learned anything from this forum.

I think this is what would go into your form page.....
<input type='hidden' name='referrer' value='<?php print $_SERVER['HTTP_REFERER']?>'>

How did I do?

LifeinAsia




msg:3349087
 8:43 pm on May 24, 2007 (gmt 0)

Unless I'm missing something, why don't you just include an identifying paramater in the link for the Reserve now" button that identifies which page you're coming from? Then just pass that paramater in the form.

Also, take it from experience- you/they will definitely want some sort of CMS developed. Travel products (or at least some of the related information) change over time, and hand editing HTML files is not productive.

adb64




msg:3349106
 9:04 pm on May 24, 2007 (gmt 0)

I also use the same method as LifeinAsia is proposing for my mailform. On each page there is a link to the mail form and one of the parameters is the URL of the referring page. This involves however some editing of the HTML files. One can not rely on the $_SERVER['HTTP_REFERER'] variable to be correct.
So for each link in the HTML files to the reservation form make change it to something like:

<a href="reserve.php?ref=http://www.example.com/product1.html>Book Now</a>

londrum




msg:3349109
 9:12 pm on May 24, 2007 (gmt 0)

if your intention is to pre-populate the reservation form with whatever it is they want to book, then you could put all of the information down as parameters in the URL. (presuming that none of it is secret)

for example, make the link to the reservation form something like this

www.example.com/reservation-form.html?city=nameofcity&amp;hotel=nameofhotel

nicebloke




msg:3349959
 5:41 pm on May 25, 2007 (gmt 0)

Bellabia, check your stickymail - I think you'll find that's what you're after? May need adapting very slightly.

colandy




msg:3353236
 9:23 am on May 30, 2007 (gmt 0)

This:

<input type='hidden' name='referrer' value='<?php print $_SERVER['HTTP_REFERER']?>'>

Was pretty close, I'd change the 'print' statement to an 'echo' statement though.

Just personal preference I think.

mehh




msg:3353241
 9:34 am on May 30, 2007 (gmt 0)

i would have done
<input type='hidden' name='referrer' value='<?=$_SERVER['HTTP_REFERER']?>'>

technically speaking you could do this with JS and .htaccess .PHP or another server side language would be better though

spietreser




msg:3359058
 1:19 pm on Jun 5, 2007 (gmt 0)

I've been looking for this as well.

In my case the form is on the homepage, which is an html file. If I would put some php code in it, I'd have to change the file extension and lose all search engine rankings!

Is this really (sending referring URL in a form) not possible using Javascript?

I'm using the following Javascript code, but it doesn't seem to work:

<!-- this goes in the page header -->
<script>
function start() {
var ref = document.getElementById('httpref');
ref.value = document.referrer;
}
onload = start;
</script>

And this line in the form:

<input type="hidden" id="httpref" value="">

Is there something wrong with the code?

Thanks in advance.

Dabrowski




msg:3359087
 1:40 pm on Jun 5, 2007 (gmt 0)

No, there's something right with your code.

ref.value = document.referer;

Unfortunately, whoever wrote the book on this couldn't spell, so only 1 'r' in referrer.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved