Solved

Submit ONCE!

Posted on 2003-10-30
14
233 Views
Last Modified: 2010-08-05
Please modify this form so it can only be submitted once:

<form method="post" action="shout.php" onsubmit="submitForm();">
     <p>Name:  
            <input name="name" type="text" value="Your Name" size="15" maxlength="15">  
            Message:
            <input name="c" type="text" value="Your Message" size="15" maxlength="25">
        </p>
        <center>
     <input id="submit" name="submit" type="submit" value="POST!">
</form>

Thanks.
0
Comment
Question by:CarBoffin
[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
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 25 total points
ID: 9649551
var submissions = 0
function submitForm(formObj)
{

  ...whatever your validation is...

  return (0 == submissions)
}

Vinny
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9649560
<form....onsubmit='if (submitForm(this)) submissions++'>

Vinny
0
 
LVL 2

Assisted Solution

by:yowser
yowser earned 25 total points
ID: 9650293
Add a name to the form:

  <form name=form1 method="post" action="shout.php" onsubmit="submitForm();">

then at the top of your existing submitForm function:

  form1.submit.disabled=true;

This will disable the submit button

regards

yowser
0
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!

 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9650338
Hi yowser,

I'm sure you meant: document.form1......
Also, you forgot to mention that it only works with browsers that supports 'disabled'

Vinny


0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9650695
another way:

<script language="javascript">

 var alreadySubmitted = false;

 function submitForm()
 {
     //  your code here

     // if everything validates properly, then do this:
     return alreadySubmitted = true;
 }

</script>  

<!-- ALSO NOTE:  in the onsubmit below, you must "return" the result of the function:  -->

<form method="post" action="shout.php" onsubmit="return submitForm();">
     <p>Name:  
            <input name="name" type="text" value="Your Name" size="15" maxlength="15">  
            Message:
            <input name="c" type="text" value="Your Message" size="15" maxlength="25">
        </p>
        <center>
     <input id="submit" name="submit" type="submit" value="POST!">
</form>

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9650714
no, no, no, forget that last post ... here is the corrected version:

<script language="javascript">

 var alreadySubmitted = false;

 function submitForm()
 {
     //  your code here

     // if everything validates properly, then do this:
     if ( !alreadySubmitted )
        return alreadySubmitted = true;
     else
        return false;
 }

</script>  
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9650722
... along with this:   onsubmit="return submitForm();"
0
 
LVL 2

Expert Comment

by:yowser
ID: 9650914
Vinny

Oops!

You're quite right - I did mean 'document.' Bit of a brain fart there!

As far as the disabled property, it would depend on what CarBoffin wants to do with the final thing. Disabling the button is a more elegant way of acheiving the functionality as it gives a visual clue that the form has been submitted.

Yowser
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9651113
yes, that should be done, but there may be more than one way to submit the form.  Sometimes pressing ENTER on a textbox will also submit.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9654950
0
 

Expert Comment

by:TrentSilverleaf
ID: 9663298
Here you are. This should work, but you need to change the form action

<HEAD>

<SCRIPT LANGUAGE="JavaScript">


<!-- Begin
var submitcount=0;

function reset() {
document.emailform.name.value="";
document.emailform.email.value="";
document.emailform.comments.value="";
}

function checkFields() {                       // field validation -
if ( (document.emailform.name.value=="")  ||   // checks if fields are blank.
     (document.emailform.email.value=="") ||   // More validation scripts at
     (document.emailform.comments.value=="") ) // forms.javascriptsource.com
   {
   alert("Please enter your name, email, and comments then re-submit this form.");
   return false;
   }

else
   {
   if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else
      {
      alert("This form has already been submitted.  Thanks!");
      return false;
      }
   }
}
//  End -->
</script>
</HEAD>

<BODY OnLoad="reset()">

<form method=post action="HTTP://WWW.MYDATABASE.COM/DTBASE" name="emailform" onSubmit="return checkFields()">

<input type=hidden name=to value="you@your-website-address-here.com">
<input type=hidden name=subject value="Feedback Form">

<pre>
Your Name:   <input type=text name="name">
Your Email:  <input type=text name="email">

Comments?

<textarea name="comments" wrap="virtual" rows="7" cols="45"></Textarea>

<input type=submit value="Submit Form!">

[ Click the submit button twice to see the script in action ]
</pre>
</form>
0
 
LVL 3

Expert Comment

by:makc
ID: 9665994
this problem is the best to solve at server side.
all you need is to generate unique submission ID before passing form to client and check before accept it later.
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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

728 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