Solved

Submit ONCE!

Posted on 2003-10-30
14
231 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

828 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