Click to See Complete Forum and Search --> : ASP session problem


mcollins
02-28-2006, 06:07 AM
Hello

I'm hoping someone can help me with this session problem I'm having...

Basically, I have a dislaimer page that users need to either accept to move on throughout the site, or decline to go back to the index. I have tried adding some code that I found on the htmlgoodies wesbite to do this but its not working - I really have no idea what I am doing by the way! The code at the top of the disclaimer page is:

<% Option Explicit %>

<% If Request.Form("accept") = "ON" then

Session("access") = "yes"

Response.Redirect "overview.asp"

End If %>

Then my form is:

<form method="POST" action="overview.asp">

"Overview.asp" is the name of the page I'd like the user to be forwarded to if they accept the disclaimer. At the moment, if they deny they still get sent to the next page - how do I stop that? Is my form action wrong? I had it originally set to the disclaimer.asp but nothing would happen when I tested the submit button.

Then on the Overview page I have added:

<% Option Explicit %>

<% If Session("access") <> "yes" then

Response.Redirect "index.asp"

End If %>

This is probably going to look so stupid I know, but I am a total newcomer. Am i almost there?

Thanks for any help!

Michelle

gintom
02-28-2006, 09:29 AM
Because you are not submitting to the disclaimer page, so the Session("access") is not being set to "yes" it is being set to "".

change your form action to "disclaimer.asp" then if it is ticked it will set the session("access") to yes and then redirect you to the overview.asp page with the session set as yes.

Hope this helps

mcollins
02-28-2006, 09:58 AM
Hello!

Thanks very much for your reply - however, now that I have changed the action to disclaimer.asp it actually stays on that page instead of forwarding to the next one! Am I mad? I just don't get it!

gintom
02-28-2006, 10:11 AM
can you show the whole of the code as it would be easier to debug for you.

mcollins
02-28-2006, 10:17 AM
OK - thanks for your help!

User gets to my disclaimer page where there are two checkboxes - accept and decline, and a sumbit button. At the top of the page I have:

<% Option Explicit %>

<% If Request.Form("accept") = "ON" then

Session("access") = "yes"

Response.Redirect "overview.asp"

End If %>

<html>

Then for the form I have:

<form method="POST" action="disclaimer.asp">
<p align="center"><span style="font-size: 11pt"><b>I accept</b> </span>
<input type="checkbox" name="accept" value="ON;
I decline</span>&nbsp;
<input type="checkbox" name="decline" value="ON;
<input type="submit" value="Submit" name="B1"></p>
</form>

Then on the page I want the user to go to once they have accepted, before the html tag I have:

<% Option Explicit %>

<% If Session("access") <> "yes" then

Response.Redirect "disclaimer.asp"

End If %>

That's all the code I have apart from the standard stuff. Hope that's Ok

Thanks!

gintom
02-28-2006, 10:27 AM
You havent closed off your input tags for the checkbox.
You have:
<input type="checkbox" name="accept" value="ON;
<input type="checkbox" name="decline" value="ON;
You should have:
<input type="checkbox" name="accept" value="ON">
<input type="checkbox" name="decline" value="ON">

mcollins
02-28-2006, 10:30 AM
duh! Thanks!! OK, I have just sorted that out. However, it's still staying on the disclaimer page when I press the submit button-its even staying there regardless of either of the check boxes being ticked

gintom
02-28-2006, 10:37 AM
Can you replace the top asp code with the following then post the results.

<% If Request.Form("accept") = "ON" then
response.write Request.Form("accept")
response.end
Session("access") = "yes"

Response.Redirect "overview.asp"

End If %>

mcollins
02-28-2006, 10:51 AM
ok, something is happening at last - it goes to a page with the word ON at the top but other than that it's blank - the url is still saying disclaimer.asp

gintom
02-28-2006, 11:19 AM
Well we know that it is going into the If statement no problem but to be honest I cannot see whay it is not redirecting.

Replace the code at top of the page to see if it redirects without the session being set.
<%
If Request.Form("accept") = "ON" then
Response.Redirect "overview.asp"
End If
%>

mcollins
02-28-2006, 11:27 AM
Hi

Yeah, it's gone back to not forwarding again - stays on the disclaimer page. I really don't understand...

chrismartz
02-28-2006, 05:53 PM
Give the following a try. Remember that you need two pages for this. One called overview.asp and one called disclaimer.asp. The following should go on disclaimer.asp as that is where the form is being submitted. Hopefully that makes sense!<%
If Request.Form("accept") = "ON" AND Request.Form("decline") <> "ON" Then
Session("access") = "yes"
Response.Redirect "overview.asp"
ElseIf Request.Form("accept") <> "ON" AND Request.Form("decline") = "ON" Then
Session("access") = "no"
Response.Write "No Access"
Else
Response.Write "Not working!"
End If
%>

JBrown1028
02-28-2006, 06:40 PM
Also look in your overview.asp file to see if there is a Response.Redirect to another page. It might be working just not doing what you are expecting