Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 7th, 2005, 03:35 AM
GaryM GaryM is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 4 GaryM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 28 sec
Reputation Power: 0
Question Help activate cookie on form submit

Hi all....

I have a cookie script on an asp web page which tracks a users access to a survey page, if the page has been visited previously by the user it then redirects the user to another page "this user has already submitted a survey"

I have now been asked to only activate the cookie only once the use has clicked on the form submit button , how do I do this ........help will be much appreciated as I am a self-taught newbie to asp coding.

below is the code I am using.
[code]
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/triples.asp" -->
<%

' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

MM_editConnection = MM_triples_STRING
MM_editTable = "dbo.sss"
MM_editRedirectUrl = "sss_thanks.asp"
MM_fieldsStr = "date|value|region|value|department|value|question 1|value|comment1|value|question 2|value|comment2|value|question 3|value|comment3|value|question 4|value|comment4|value|question 5|value|comment5|value|question 6|value|comment6|value|question 7|value|comment7|value|question 8|value|comment8|value|question 9|value|comment9|value|question 10|value|comment10|value|add_comment|value"
MM_columnsStr = "Date|',none,NULL|Region|',none,''|department|',non e,''|Score1|none,none,NULL|comment1|',none,''|scor e2|none,none,NULL|comment2|',none,''|score3|none,n one,NULL|comment3|',none,''|score4|none,none,NULL| comment4|',none,''|score5|none,none,NULL|comment5| ',none,''|score6|none,none,NULL|comment6|',none,'' |score7|none,none,NULL|comment7|',none,''|score8|n one,none,NULL|comment8|',none,''|score9|none,none, NULL|comment9|',none,''|score10|none,none,NULL|com ment10|',none,''|add_comment|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
set sss = Server.CreateObject("ADODB.Recordset")
sss.ActiveConnection = MM_triples_STRING
sss.Source = "SELECT * FROM dbo.sss"
sss.CursorType = 0
sss.CursorLocation = 2
sss.LockType = 3
sss.Open()
sss_numRows = 0
%>
<html>
<head>
<SCRIPT language=JavaScript>
<!-- Hide this script from old browsers --
/*
It is brought to you by Eric Jarvies, Lewis Sellers, Giuseppe Lombardo,
Kurt Anderson, and David Medinets.
*/
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function ResetCounts(name)
{
visits = 0;
SetCookie("visits", visits, expdate , "/", null, false);

location.reload();

}
// -- End Hiding Here -->
</SCRIPT>
<title>Staff_Satisfaction</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
// start cookie check here
var expdate = new Date();
var visits;
// Set expiration date to a month from now.
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 28));
if(!(visits = GetCookie("visits")))
visits = 0;
visits++;
SetCookie("visits", visits, expdate, "/", null, false);
//document.write("<STRONG>"+"Your browser has visited this page "+" </STRONG>"
//+"<FONT COLOR=0000FF><STRONG>"+visits+"</STRONG></FONT>"
//+"<STRONG>"+" time(s)."+"</STRONG>");
if(visits == 1)
document.write("<P><FONT SIZE=+1><EM>"+"Welcome" +"</STRONG></EM></FONT.");;
if(visits >= 2)
window.location.replace("http://ecintranet/beenhere.html") ;

// -->end cookie script
</SCRIPT>
<!--
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)

//-->
</script>

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Help activate cookie on form submit


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway