form submit more than once

P

Paul M

Hi
Has anyone found away to stop a form bieng submitted to a database more than
once. At the moment I can submit the data to a database recieve the
confirmation page press the back button then re submit the entry again.
Thanks
Paul M
 
P

Peter R. Fletcher

You could have the confirmation page set a cookie which causes an
immediate jump (back) to it from the form page if it is reloaded.

Hi
Has anyone found away to stop a form bieng submitted to a database more than
once. At the moment I can submit the data to a database recieve the
confirmation page press the back button then re submit the entry again.
Thanks
Paul M

Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
P

Paul M

Thanks
But How
Paul M
Peter R. Fletcher said:
You could have the confirmation page set a cookie which causes an
immediate jump (back) to it from the form page if it is reloaded.



Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher
 
P

Peter R. Fletcher

The following is not guaranteed and has not been tested, but should
work.

Create a new file (we'll call it "functions.js" in the web's root
folder. Cut and paste the Javascript code (which is tested, and does
work!) below (within the <SNIPPET> block!!) into it:

<SNIPPET>
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}
</SNIPPET>

We'll assume also that your Form file is called myform.htm, that your
confirmation page file is called myconfirm.htm, and that they are both
in the root directory of your web. All file references should be
adjusted appropriately to reflect the real file names and locations.

Cut and paste the following into the HEAD section of _both_ HTML
files:

<SNIPPET>
<SCRIPT LANGUAGE="JavaScript" SRC="functions.js">
</script>
</SNIPPET>

Cut and paste the following just after the <BODY> tag in
myconfirm.htm:

<SNIPPET>
<SCRIPT LANGUAGE="JavaScript">
var now = new Date();
fixDate (now);
now.setTime(now.getTime() + 5*60000);
setCookie ("FormSubmitted", 1, now,"/");
</script>
</SNIPPET>

This will set a cookie that persists for 5 minutes after the confirm
page is displayed - to change this time, substitute the time (in
minutes) for which you want it to persist for the number 5 in the
third line of the code immediately above.

Cut and paste the following just after the <BODY> tag in myform.htm:

<SNIPPET>
<SCRIPT LANGUAGE="JavaScript">
if (getCookie ("FormSubmitted")) location.href = 'myconfirm.htm';
</script>
</SNIPPET>

If you like, you can redirect someone who goes back to the form within
your preset time to a totally different page - e.g. one that says:
"You should't submit the form more than once!" - just give its name
instead of that of myconfirm.href in the script command immediately
above.On Sat, 20 Aug 2005 17:09:35 +0100, "Paul M"
Thanks
But How
Paul M

Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
P

Paul M

Thanks Peter
I will Give it a go
Paul M
Peter R. Fletcher said:
The following is not guaranteed and has not been tested, but should
work.

Create a new file (we'll call it "functions.js" in the web's root
folder. Cut and paste the Javascript code (which is tested, and does
work!) below (within the <SNIPPET> block!!) into it:

<SNIPPET>
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}
</SNIPPET>

We'll assume also that your Form file is called myform.htm, that your
confirmation page file is called myconfirm.htm, and that they are both
in the root directory of your web. All file references should be
adjusted appropriately to reflect the real file names and locations.

Cut and paste the following into the HEAD section of _both_ HTML
files:

<SNIPPET>
<SCRIPT LANGUAGE="JavaScript" SRC="functions.js">
</script>
</SNIPPET>

Cut and paste the following just after the <BODY> tag in
myconfirm.htm:

<SNIPPET>
<SCRIPT LANGUAGE="JavaScript">
var now = new Date();
fixDate (now);
now.setTime(now.getTime() + 5*60000);
setCookie ("FormSubmitted", 1, now,"/");
</script>
</SNIPPET>

This will set a cookie that persists for 5 minutes after the confirm
page is displayed - to change this time, substitute the time (in
minutes) for which you want it to persist for the number 5 in the
third line of the code immediately above.

Cut and paste the following just after the <BODY> tag in myform.htm:

<SNIPPET>
<SCRIPT LANGUAGE="JavaScript">
if (getCookie ("FormSubmitted")) location.href = 'myconfirm.htm';
</script>
</SNIPPET>

If you like, you can redirect someone who goes back to the form within
your preset time to a totally different page - e.g. one that says:
"You should't submit the form more than once!" - just give its name
instead of that of myconfirm.href in the script command immediately
above.On Sat, 20 Aug 2005 17:09:35 +0100, "Paul M"


Please respond to the Newsgroup, so that others may benefit from the
exchange.
Peter R. Fletcher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top