Home
Web Front-end
JS Tutorial
Two ways to prevent repeated submission of forms in js_javascript skills



Two ways to prevent repeated submission of forms in js_javascript skills
May 16, 2016 pm 05:20 PM
First type: is marked with flag. The following code sets the checkSubmitFlg flag:
<script language=""javascript"">
var checkSubmitFlg = false;
function checkSubmit(){
if (checkSubmitFlg ==true){ return false; //When the form is submitted once, checkSubmitFlg will become true, and it will not be submitted based on judgment.
}
checkSubmitFlg ==true;
return true;
}
< /script >
< form name=”form1” method=”post” onsubmit=”return checkSubmit();”>
………..< /form>
The second type: is set in the onsubmit event to invalidate the submit button after the first submission. The code is as follows:
<form action=”about:blank” method=”post” onsubmit =”getElementById('submitInput').disabled=true;return true ;" target="_blank">
<input type="submit" id="submitInput"/>
</form>
</body>
</ html>
</script>
Because the program source code conflicts with the WIN2000 registry, an invalid page will appear after the post is sent. As a result, there are many non-malicious duplicate posts in the forum. Later I came up with a way to use JS to avoid repeated submissions. Here is part of the source code:
<script Language='JavaScript'>
function formsubmit() {
Today = new Date();
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowSecond = Today.getSeconds();
var mysec = (NowHour*3600) (NowMinute*60) NowSecond;
if((mysec-document.formsubmitf. mypretime.value)>600)
//600 is just a time value, which means repeated submission is prohibited within 5 minutes. Set the value as you like
{
document.formsubmitf.mypretime.value=mysec;
}
else
{
alert(' Just click once, please do not submit again! Please wait! Thank you for your cooperation! ');
return false;
}
document.forms.formsubmitf.submit();
}
</script>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<form name=formsubmitf id ="the" method="post" action="XXX.asp">
<input type=hidden name='mypretime' value='0'> //This sentence cannot be missing, use implicit variables to pass an initial time value
//Here is the content you want to submit
<input type="button" value="written" name="button1" class="4round" onclick='formsubmit()'> <font class="red">(Please click once , wait patiently! )</font> <input type="reset" value="rewrite" name="button2" class="4round">
</form>
Using this code, the number of duplicate posts in the forum has been significantly reduced. However, there is a disadvantage. The detection will not work after refreshing once. The advantage is that it uses JS detection and does not require additional permission support. As for the effect, it depends on whether you use it or not. It’s up to you (it’s best to add detection to both the front-end and back-end)
Copy code The code is as follows:
<script language=""javascript"">
var checkSubmitFlg = false;
function checkSubmit(){
if (checkSubmitFlg ==true){ return false; //When the form is submitted once, checkSubmitFlg will become true, and it will not be submitted based on judgment.
}
checkSubmitFlg ==true;
return true;
}
< /script >
< form name=”form1” method=”post” onsubmit=”return checkSubmit();”>
………..< /form>
The second type: is set in the onsubmit event to invalidate the submit button after the first submission. The code is as follows:
Copy code The code is as follows:
<form action=”about:blank” method=”post” onsubmit =”getElementById('submitInput').disabled=true;return true ;" target="_blank">
<input type="submit" id="submitInput"/>
</form>
</body>
</ html>
</script>
Because the program source code conflicts with the WIN2000 registry, an invalid page will appear after the post is sent. As a result, there are many non-malicious duplicate posts in the forum. Later I came up with a way to use JS to avoid repeated submissions. Here is part of the source code:
Copy the code The code is as follows:
<script Language='JavaScript'>
function formsubmit() {
Today = new Date();
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowSecond = Today.getSeconds();
var mysec = (NowHour*3600) (NowMinute*60) NowSecond;
if((mysec-document.formsubmitf. mypretime.value)>600)
//600 is just a time value, which means repeated submission is prohibited within 5 minutes. Set the value as you like
{
document.formsubmitf.mypretime.value=mysec;
}
else
{
alert(' Just click once, please do not submit again! Please wait! Thank you for your cooperation! ');
return false;
}
document.forms.formsubmitf.submit();
}
</script>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<form name=formsubmitf id ="the" method="post" action="XXX.asp">
<input type=hidden name='mypretime' value='0'> //This sentence cannot be missing, use implicit variables to pass an initial time value
//Here is the content you want to submit
<input type="button" value="written" name="button1" class="4round" onclick='formsubmit()'> <font class="red">(Please click once , wait patiently! )</font> <input type="reset" value="rewrite" name="button2" class="4round">
</form>
Using this code, the number of duplicate posts in the forum has been significantly reduced. However, there is a disadvantage. The detection will not work after refreshing once. The advantage is that it uses JS detection and does not require additional permission support. As for the effect, it depends on whether you use it or not. It’s up to you (it’s best to add detection to both the front-end and back-end)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial

8 Stunning jQuery Page Layout Plugins
