PDA

View Full Version : Deactivate Submit Button after clicking it


Thomas P
03-02-2004, 09:14 PM
Hello,

saw this on an IPB and must say: Neato! :)

Checked the JS, seems easy, but didn't werk on my testing forum.

Is there a hackette for this around here? :)

thx,
-Tom

Andreas
03-02-2004, 09:34 PM
Hmm ... why would you need this? After a user hits submit the page will be replaced anyway ...

assassingod
03-02-2004, 09:39 PM
Hmm ... why would you need this? After a user hits submit the page will be replaced anyway ...
Some people on slow connections might mistake their speed for an error on the site, and hit submit twice.

Thomas P
03-04-2004, 09:40 PM
Yup, plus it's just pretty neat.

Matt D
03-06-2004, 06:37 PM
Put this into the <head> </head> part of your vBulletin forum

<script>
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>

Next, look in your templates for the "<form" tags in which you want to incorporate "submit once" validation, and add this inside the <form tag that is applicable to your needs (ie <form action="something.php" putcodehere>

onSubmit="submitonce(this)"

Matt D
03-06-2004, 07:02 PM
Well, my instructions were pretty blunt, so I'll follow up with some more specific instructions...

Place the <head> </head> part of the code into your header include field (this can be found on the general style editing page in your vBulletin admin control panel).

Next, go to the template section and open the newthread template. Find where the template says <form

Inside this tag replace onSubmit="return validate(this)" with onSubmit="return submitonce(this)"

This replaces a javascript dialog box that will say "You didn't fill in the fields" with the deactivate submit button on the touch of the button. It will still validate the fields manually and display an error message on the next page saying they need to go back and fill in all the fields. I'm no javascript expert, so I didn't research or even attempt ways of incorporating both types of validation into one check... If you want that, you'll need to wait for someone to contribute that, or find a way yourself :)

You'll need to take the above steps in all applicable templates that you'd like the form submit button disabled on click (like "newreply", "newpoll" etc...). I suggest searching for all templates that have <form in it and adding / replacing the code as outlined above.

Thomas P
03-07-2004, 03:32 PM
Okay, thanks! :)

What I did now is to insert the following code in the JavaScript parts of the newreply and newthread (editpost, pm ...) template etc.

Just insert this snippet theform.submit.disabled=true; before the return true; part. :)

E.g.:


<script language="javascript">
<!--
var postmaxchars = $postmaxchars;
function validate(theform) {
if (theform.message.value=="") {

(...)

return false; }
else { theform.submit.disabled=true; return true; }
} else { theform.submit.disabled=true; return true; }
}
function checklength(theform) {

(...)

//-->
</script>


Here are the templates where the code resides:

showthread_replybox (Quick reply hack vB2)
editpost, newreply, newthread, priv_sendprivmsg, priv_forwardmultiple, priv_sendtobuddies


hth