Click to See Complete Forum and Search --> : Hidden fields in a form
Stevie D
12-07-2003, 02:08 PM
Hi, I hope someone can help me out, or tell me that this is definitively not possible...
I've decided that to put an email contact form on my website rather than just a mailto: link. That much is running fine now. But whereas before, I could put ?subject= in the link, to see which page the user had followed the mail link from (from a choice of over 100, sometimes it is important), now I just have one page with the contact form that is called up, whichever page the user was on.
So (getting to the question at last), is it possible to put something on the original page (the referring page?) that sets a hidden field in the form?
TIA for your help,
Stevie
ray326
12-07-2003, 07:05 PM
The form page can set a hidden input to the value of the referring page. You obtain it using document.referrer.
Stevie D
12-08-2003, 01:04 PM
Thanks, Microsoft Hater, but for the purposes of this discussion, please assume that I know nothing about Javascript (which is not quite true, but not far off).
How can I use "document.referrer" to get a hidden field?
TIA
ray326
12-08-2003, 03:42 PM
You'd put something like this in the form (name="myform", e.g.) on your new page.
<input type="hidden" name="caller" value="unknown">
Then you'd use Javascript, maybe in a body onload handler, to set the "real" value.
document.myform.caller.value = document.referrer
Now when "myform" is posted it will carry along the href of the page that called it.
Note, none of this was tested so a detail or two may be wrong.
Stevie D
12-08-2003, 04:03 PM
That's great, thanks!
Took me a few attempts to remember JS is case sensitive, but it appears to be working fine now.
Cheers,
Stevie
Stevie D
01-03-2004, 11:06 AM
Bum :-(
And document.referrer seemed to be doing such a good job, until I realised that it wasn't appearing on the form data, and I had only tested it in Opera, not NS or IE. And it doesn't seem to work in either of them - not as a <BODY onLoad...> nor as a script in the <HEAD>... not dumped in some random place cos I was getting fed up.
Does anyone else have any ideas?
The referrer document will be another page on my website - if I create a form on that page with the same name as the next one, and set a value there, will it be remembered on the next page?
Thinking about it - no, probably not - that would create all sorts of security problems when two different people had different forms with the same name.
What I need to do now is to train everyone who uses my website to use Opera or some other fully-featured browser...
Pittimann
01-04-2004, 12:59 AM
Hi!
Can you please post the code of the page with the contact form?
Cheers - Pit
Stevie D
01-04-2004, 05:04 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<HTML>
<HEAD>
<Title>Email contact</Title>
<Link Rel=Stylesheet Type="text/css" HRef="email.css" Media=screen>
<Link Rel=Home Title="Home page" HRef="http://www.sjd117.freeserve.co.uk/yorkbus/">
<Link Rel=Index Title="Index of services" HRef="http://www.sjd117.freeserve.co.uk/yorkbus/search-frame.htm">
<Script Language="JavaScript" type="text/javascript">
<!--
function validate()
{
x=document.Message
at=x.visitor_email_address.value.indexOf("@")
if (at == -1)
{
alert("Please check your e-mail address is correct")
return false
}
}
//-->
</Script>
</Head>
<BODY onLoad="document.Message.Page.value = document.referrer;">
<H2 Style="border-bottom:4px #47b7b7 ridge;">Email the Busmaster</H2>
<DIV>If you have a complaint about the bus service, contact the bus company, <B>not me</B></Div>
<DIV>If you want to know about fares, phone Traveline on 0870 608 2 608, <B>not me</B></Div>
<DIV>If you have any other query, I will do my best to help</Div>
<FORM Method=Post Action="http://www.response-o-matic.com/cgi-bin/rom.pl" Style="border:2px #47b7b7 solid; padding:0.2em;" Name=Message onSubmit="return validate()">
<INPUT Type=Hidden Name="your_email_address" Value="busmaster@sjd117.freeserve.co.uk">
<INPUT Type=Hidden Name="your_name" Value="Busmaster">
<INPUT Type=Hidden Name="email_subject_line" Value="Yorkbus contact">
<INPUT Type=Hidden Name="Page" Value="">
<INPUT Type=Hidden Name="thank_you_title" Value="Thank you for your message">
<INPUT Type=Hidden Name="return_link_url" Value='http://www.sjd117.freeserve.co.uk/yorkbus/" onclick="window.close()"'>
<INPUT Type=Hidden Name="return_link_name" Value="Close window">
<INPUT Type=Hidden Name="background_color" Value="Teal">
<INPUT Type=Hidden Name="text_color" Value="#ffffff">
<INPUT Type=Hidden Name="link_color" Value="#ffd700">
<INPUT Type=Hidden Name="visited_link_color" Value="#ffd700">
<INPUT Type=Hidden Name="active_link_color" Value="#ffffcc">
<TABLE>
<TR><TD Class=T>Name:</TD>
<TD Class=T><INPUT Name="visitor_name" Size=40 Style="font-family:trebuchet ms, verdana, tahoma;"></TD></TR>
<TR><TD Class=T>Email:</TD>
<TD Class=T><INPUT Name="visitor_email_address" Size=40 Style="font-family:trebuchet ms, verdana, tahoma;"></TD></TR></Table>
<P>Your message:
<BR><TextArea Name=Message Rows=5 Cols=50 Style="font-family:trebuchet ms, verdana, tahoma;"></Textarea></P>
<P><INPUT Type=CheckBox Name=Subscribe> Subscribe to mailing list?
<BR><SPAN Class=S>If you tick this box, I will send you an email when the website is updated, no more than once a week. Your email address will not be used for any marketing purposes or given to anyone else</Span></P>
<P Align=Right><INPUT Type=Submit Value="Send Message" Style="background-color:#ffd700; font-family:trebuchet ms, verdana, sans serif;"> <INPUT Type=Reset Value="Cancel" Style="color:gray; font-family:trebuchet ms, verdana, sans serif;" onClick="window.close(); return true"></P>
...
[Then a load of form stuff]
...
</Div>
</Form>
</Body>
</HTML>
Pittimann
01-04-2004, 08:46 AM
Hi!
Due to the fact that your cancel button is designed for closing the window, I guess that this contact form (the page with it) is opened in a new window by clicking the appropriate link on one of your pages.
If this is true, you can get around the problems with document.referrer just by using opener.location instead...
Cheers - Pit
Stevie D
01-04-2004, 09:45 AM
Excellent deduction!
Thank you very much, that works fine in Opera, IE and NS - brilliant :-)
I'm not even going to wonder why Microsoft and Netscape allow the use of opener.location and not document.referrer ...