Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnLoad Test Value from passed Variable

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
US
Does anyone know how I could read in a hidden value that was submitted from a previous page? Specifically, I need to validate whether or not someone has just come from a previous page "disclaimer.html". So, basically when someone clicks on the "I Agree" button they would go to viewer.html where it would read the value of a hidden field from a form on disclaimer.html. If they click on the "I disagree button I would either have the disclaimer page reload, or an error page come up (with a link back to the disclaimer page telling them that they can't view the page without agreeing to the disclaimer. If the person has not come from the disclaimer page, then an error page would open. This would force them to agree to the disclaimer before being allowed to view the page. I want to prevent someone from just being able to type in the url, without agreeing to the disclaimer. Any help would be greatly appreciated. The boss would like this figured out by the end of the week, and I'm just learning this stuff. Thanks!!!
 
P.S. I cannot change the name of the viewer.html page (ie., can't change it to viewer.asp, etc.,)
 
Do You use ASP or JSP or static HTML ? Water is not bad as long as it stays out human body ;-)
 
Well, I've never worked with JSP. I know HTML and am learning Javascript and VBScript. It doesn't really matter which I use, as long as the task is accomplished and I don't have to change the name of the viewer.html page to .asp. Thanks.
 
May be you can set a cookie when the user clicks on the "agree" button on "disclaimer.html" and then check on load of "viewer.html" if the cookie is set. If no redirect to error page. Water is not bad as long as it stays out human body ;-)
 
I was almost positive that I wouldn't be able to change the name of my viewer.htm file to viewer.asp, because it's part of a very complex website that uses XML and interactive maps. I just did a search of all the pages in the website and found that it's used as the main page for the website, so I see no reason why I can't rename the extension to .asp. So, on that note, I'd rather use ASP/VBScript so the users won't see the code. How could I accomplish my task using that method. When viewer.asp opens, I'd have to verify that they agreed to the disclaimer (by passing a value from a hidden form perhaps, but then again, I'm a newbie) If the request.form field value is null, then they would be referred to an error page (with a link to the disclaimer page) telling them they must agree to the disclaimer or they can't open viewer.asp??? Any ideas on how to best accomplish this??? Thanks a million!!
 
Haaaa...
If you can use ASP, this is simplier. You pointed it. on disclaimer page, fill the value of hidden field depending on wich button has been clicked (for exemple with "AGREE" and "DISAGREE").
Then, in viewer.asp, write the following code :
Code:
<%
if request.form(&quot;myHiddenId&quot;).value = &quot;DISAGREE&quot; then
  Response.redirect(&quot;error.html&quot;)
end if
%>
Water is not bad as long as it stays out human body ;-)
 
But what can I do to prevent the person from bypassing the disclaimer page by just typing in the url? Here's my present code (since I'm a newbie, forgive any bad ideas). There are 3 pages. Disclaimer.htm, DisclaimerError.htm, and Viewer.asp. If the person came from the disclaimer page and clicked on the agreed button the Viewer.asp page would open with no problem. If they click disagree, the page would go to DisclaimerError.htm. But if they just type in the url or who knows where, I want them to be sent to the DisclaimerError.htm (or DisclaimerError.asp, whatever is necessary)

Code for Disclaimer (test) page:

<html>
<head>
<title>Disclaimer Page</title>
</head>
<body text=&quot;#000000&quot; bgcolor=&quot;#FFFFCC&quot; link=&quot;#0000EE&quot; vlink=&quot;#551A8B&quot; alink=&quot;#FF0000&quot;>
<b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3></font></b>&nbsp;<b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000099&quot;><font size=+3></font></font></font></b>
<center>
<p><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3>Disclaimer Page</font></font></font></b><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000099&quot;><font size=+3></font></b>
<p><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot;>By clicking below
you agree to this stuff!!!</font></b></center>
<center>
<table COLS=2 WIDTH=&quot;60%&quot;>
<tr>
<td>
<form method=&quot;POST&quot; action=&quot;viewer.asp&quot; name=&quot;frmAgree&quot;>
<input type=&quot;hidden&quot; name=&quot;agreed&quot; value=&quot;&quot;>
<center>
<table COLS=2 WIDTH=&quot;60%&quot; >
<tr>
<td>
<center><input type=&quot;submit&quot; value=&quot;Agree&quot; onClick=&quot;frmAgree.agreed.value='yes';&quot;></center>
</td>
<td>
</center><input type=&quot;submit&quot; value=&quot;Disagree&quot; onClick=&quot;frmAgree.agreed.value='no';&quot;;></center>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</center>
<b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot;></font></b>
</body>
</html>

Code for the DisclaimerError.htm test Page:
<html>
<head>
<title>Disclaimer Page</title>
</head>
<body text=&quot;#000000&quot; bgcolor=&quot;#FFFFCC&quot; link=&quot;#0000EE&quot; vlink=&quot;#551A8B&quot; alink=&quot;#FF0000&quot;>
<b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3></font></b>&nbsp;<b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000099&quot;><font size=+3></font></font></font></b>
<center>
<p><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3>Error
Page...</font></b>
<p><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot;>I'm sorry you
cannot view this page without agreeing to our Disclaimer.</font></b>
<p><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot;><a href=&quot;Disclaimer.htm&quot;>Click
here</a> to go to the Disclaimer Page.</font></b></center>
</body>
</html>

Code for the Viewer.asp test page:
<%Option Explicit
Response.buffer = &quot;true&quot;

'Declare variables
Dim strAgreed
'Grab variables from the querystring.
strAgreed=Request.Form(&quot;agreed&quot;)

If strAgreed = null or strAgreed = &quot;&quot; Then
Response.Redirect &quot;DisclaimerError.htm&quot;
End If
%>
<html>
<head>
<title>viewer</title>
</head>
<body text=&quot;#000000&quot; bgcolor=&quot;#FFFFCC&quot; link=&quot;#0000EE&quot; vlink=&quot;#551A8B&quot; alink=&quot;#FF0000&quot;>
<center><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3>This
is the viewer.htm page.</font></b>
<br><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3>You
have successfully viewed and agreed to the disclaimer!</font></b>
<br><b><font face=&quot;Arial,Helvetica&quot; color=&quot;#000099&quot; size=+3>Thank
You!!!</font></b></center>
</body>
</html>

Thanks for your help!!!
 
These lines of code you wrote in Viewer.asp will do the stuff :
Code:
strAgreed=Request.Form(&quot;agreed&quot;)

If strAgreed = null or strAgreed = &quot;&quot; Then
  Response.Redirect &quot;DisclaimerError.htm&quot;
End If
In effet, if you type in the url of viewer.asp directly,
Code:
&quot;Request.Form(&quot;agreed&quot;)
will be null or empty string and then you'll be redirected. Try it, it think this should work.
If you got an error, try the following :
Code:
on error resume next  'Starts error handling
strAgreed=Request.Form(&quot;agreed&quot;)
if err.number <> 0 then
  err.clear
  strAgreed=&quot;&quot;
end if
on error goto 0    'Stops error handling

If you don't have an error and the error page is never shown, add the following line INSIDE YOUR BODY TAG :
Code:
<% response.write(&quot;strAgreed=[&quot; & strAgreed & &quot;]&quot;) %>
This'll write the exact value of the var in your page so you'll can adapt your test.

Note : in Vb, don't use
Code:
&quot;if strAgreed = null...&quot;
but
Code:
&quot;if not isNull(strAgreed)...&quot;
Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top