Solved

can anyone tweak my form cookie?

Posted on 2001-06-02
4
162 Views
Last Modified: 2011-09-20

I got this script from Netmag the other day and I'd like to tweak it a bit but I can't seem to get it right.

The script warns users that they have already submitted a form when they click on submit, it gives the date/time of submission and gives then the option to re-submit.

And it goes like this:

-------------------------

<FORM ACTION="http://www.netmag.co.uk" NAME="myform">
<INPUT TYPE=BUTTON VALUE="Submit This Form" onClick="mySubmit()">
</FORM>

</CENTER>

<SCRIPT>
var alreadyclicked = "no";
var cookiename = "datesubmitted";

function mySubmit(){
   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart +
cookiename.length + 1, myend+1);

      var myconfirm = "You submitted this form at ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
      ret = confirm(myconfirm);
      if (ret == false){
         return;
      }
   }

   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.myform.submit();
}

</SCRIPT>

------------------

I would like to tweak this script in two ways.

Firstly, I would like to REMOVE the option to re-submit,
and
secondly, I would like to set an expiry date of 3 months.

Any hot tips would be massively gratefully received.

Thanks.
0
Comment
Question by:GabrielleReid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
TTom earned 50 total points
ID: 6149193
Without getting too messy, it seems that setting the expiry date is a matter of changing the date on your cookie setting.

In order to prevent the resubmission, all you need to do is to determine if the cookie exists.  If it does, the form should not be resubmitted.


function mySubmit() {
cookiename = "alreadysubmitted"
if (document.cookie.indexOf(cookiename) > -1){
  alert("You can only submit this form once every three months."
  return false;
} else {
  mydate = new Date();
  mydate.setMonth(mydate.getMonth() + 3)
  document.cookie = cookiename + "=" + mydate;
  return true;
}

<form onsubmit="return mySubmit();">

This should do it for you.

Tom
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7811048
This question has been abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
   In the absence of responses, I may recommend DELETE unless it is clear
   to me that it has value as a PAQ.  Silence = you don't care
</note>

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7909538
It is time to clean this abandoned question up.  

I am putting it on a clean up list for CS.

<recommendation>
points to TTOM

</recommendation>

If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Cd&
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7958421
Comment from expert accepted a answer

Computer101
E-E Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Debugging Html 8 32
Link not working 6 43
Rotate images for Web Page 11 28
list:contains ... search finds as it should but how could I get the number items found? 3 25
This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question