a little asp help

  • Thread starter Thread starter chris leeds
  • Start date Start date
C

chris leeds

Hi all,
I've got a link that calls another page with a form on it. this link could
be on any page.
I want to make a hidden form field to forward the referring page to the
handler.
I am assuming on the form I would use:
request.ServerVariables("HTTP_REFERER")
to get the address of the page that opened the form but I can't figure out
how to write it as the value of the hidden form field.
TIA!
 
Chris,

You don't want to use "request.ServerVariables("HTTP_REFERER")" because if
user have Norton Antivirus or Personal Firewall installed, the default is
that the referral value is not sent by the browsers.

In order to past a hidden value, you would have to use a form button
enclosed in form fields. However depending on what you are actually trying
to accomplish, using a QueryString might be a workable solution.

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
sorry for the density but here's where I'm at:
on the form I've got this:
<input type="hidden" name="thelink" value="<%
request.ServerVariables("HTTP_REFERER") %>">

which seems to work, at least it doesn't throw an error.

what I'm having trouble with is this:
on the action url (the handler) I've got this:
TheLink=request("thelink")

but I'm having a hard time getting it to write to the body of the email.
I've tried a bunch of stuff and here's where I'm at:

objNewMail.Body = "One of your friends thought you would be interested in
this:" & vbcrlf & vbcrlf & vbcrlf & "Link:" & vbcrlf & (TheLink)
 
"Link: " & Request.Form("thelink") & vbCrLf & vbCrLf

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
didn't work. I just got a blank email with everything but the link.

here is what that section of the handler looks like with the change you
suggested:

<%
sendersName="NE Digital Photo"
sendersEmail="Mail@spammy_nedp.not"
emailSubject="Something You Should See"
EmailRecipient=request("EmailRecipient")
TheLink=request("thelink")

' create email
Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = sendersName & "<" & sendersEmail & ">"
objNewMail.Subject = EmailSubject
objNewMail.To = EmailRecipient
objNewMail.Body = "One of your friends thought you would be interested in
this:" & vbcrlf & vbcrlf & vbcrlf & "Link:" & Request.Form("thelink")
 
<form action="sendLink.asp" method=post target="_self"onSubmit="return
checkEmail(this)">
<label class="frame" for="fp4">Recipient's Email</label><input type="text"
name="emailrecipient" maxlength="255" size="20" id="fp4"><br>
<input type="hidden" name="thelink" value="<%
request.ServerVariables("HTTP_REFERER") %>">
<input type="submit" name="submit" value="Send">
<input type="reset" value="Clear" name="B1">

</form>
 
<%
sendersName="NE Digital Photo"
sendersEmail="Mail@spammy_nedp.not"
emailSubject="Something You Should See"
EmailRecipient=request.form("EmailRecipient")
TheLink=request.form("thelink")

' This will let you see the value that is being submitted.
Response.Write TheLink

' create email
Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.From = sendersName & "<" & sendersEmail & ">"
objNewMail.Subject = EmailSubject
objNewMail.To = EmailRecipient
objNewMail.Body = "One of your friends thought you would be interested in
this:" & vbcrlf & vbcrlf & vbcrlf & "Link:" & TheLink

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
Change

request.ServerVariables("HTTP_REFERER")

to

Request.ServerVariables("SCRIPT_NAME")

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
did both things you suggested and the email I get still doesn't have the
link. it looks like this:

One of your friends thought you would be interested in this:



Link:
 
The page with the hidden form field is a .asp page, correct?

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
yes.

Thomas A. Rowe said:
The page with the hidden form field is a .asp page, correct?

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
Ok and the pages that you want to include a link to are also .asp page,
correct?

If so, below is what I have used in one of my projects, so that when a user
select to contact the webmaster, the webmaster knows what page the user was
on when they clicked the link to the contact form, and this basically the
same thing you are trying to do.

Include the following on the top of all pages before the <html> tag:

<%
Dim SPage
SPage = Request.ServerVariables("URL")
Session("SPage") = SPage
%>


Then on your form page add the following as a hidden form field:

<input type="hidden" name="thelink" value="<%=Session("SPage")%>">

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
I don't think the form is picking up and sending the value for the referring
page. here is the form's content:

<form action="sendLink.asp" method=post target="_self"onSubmit="return
checkEmail(this)">
<label class="frame" for="fp4">Recipient's Email</label><input type="text"
name="emailrecipient" maxlength="255" size="20" id="fp4"><br>
<input type="hidden" name="thelink" value="<%
request.ServerVariables("HTTP_REFERER") %>">
<input type="submit" name="submit" value="Send">
<input type="reset" value="Clear" name="B1">

</form>

I don't think it's passing the value for the fomr field "thelink" because
the response.write statement on the form handler isn't writing it to the
page.
 
Chris,
you need an = sign in the form value -
<input type="hidden" name="thelink"
value="<%=request.ServerVariables("HTTP_REFERER") %>">
but there's a few situations in which referer doesn't work, so you might
want to add the url to your link, eg
<a
href="TellAFriend.asp?link=<%=request.servervariables("SCRIPT_NAME")%>">Tell
A Friend</a>
and then pick it up in your form
<input type="hidden" name="thelink" value="<%=request("link") %>">
 
Neither of those worked for me either.
I just did it differently (read: the way I found the script). I can't
believe something so seemingly easy has gotten the better of me. ;-)
Thanks Thomas and Jon.
 
I thought there must have been something you weren't telling us :-) . You'd
probably do something like this

<a href="form.asp?link=<%=request.servervariables("script_name")%>"
target="_blank"
onclick="window.open(this.href,'mywin','width=200,height=200'); return
false;">link</a>
 
I finally figured out what was preventing me from passing the referrer
through the form to the handler! I was popping up the form with JavaScript
and apparently that is obfuscating the referrer! I've got it with two
links: one that's just a regular hyperlink "_blank" and another that's a
JavaScript pop-up. the regular one passes the value the popped-up form
doesn't.
Now all I've got to do is figure out why it's doing this. I've got my
suspicions that it's (this.href,.....
 
ok, that'll send me to the form with a query string. why are you using
script_name rather than http_referrer?
 
because we want the name of the page that the guy wants to recommend to be
passed to the form - then on the form we retrieve it with
<input type="hidden" name="link" value="<%=request("link")%>">
http_referer will never work on links opened with script - so it's not going
to be any use to you here

Cheers,
Jon
 
thanks Jon!
I've got it!! I had to modify the form handler to write the http:// part
since the script_name was only the /folder/page.extn part but it's working!!
thanks again to both Thomas and Jon
 
Back
Top