Page 1 of 1

Diabling submit buttons

Posted: Wed Apr 02, 2003 11:50 am
by k_nitin2k
Hi,
i am a newbie in PHP. Is there any way in PHP to disable submit buttons after clicking it once or atleast disable them for a while(5-10) secs.
Thanks...

Posted: Wed Apr 02, 2003 11:54 am
by m3mn0n
eh?...

Posted: Wed Apr 02, 2003 12:54 pm
by hedge
You have to do it with javascript.

Posted: Wed Apr 02, 2003 1:29 pm
by volka

Code: Select all

<html>
	<head>
		<script type="text/javascript">
			function toggleButton(sId)
			&#123;
				o = document.getElementById(sId);
				if (o != null)
				&#123;
					if (o.disabled)
						o.disabled = false;
					else
						o.disabled = true;
				&#125;
			&#125;
			
		</script>
	</head>
	<body>
		<form method="POST" onSubmit="toggleButton('s1'); return false;" >
			<input type="submit" id="s1" disabled="disabled" />
			<script type="text/javascript">
				setTimeout("toggleButton('s1')", 5000);
			</script>
		</form>
	</body>
</html>
actual posting is suppressed.
Without javascript (or disabled) users cannot post at all :-S

Posted: Wed Apr 02, 2003 7:34 pm
by phice
Or... Do it the way I do it. ;)

Code: Select all

<SCRIPT LANGUAGE=javascript>
<!--
var submitDone;
submitDone = 0;
	function preventDoublePosts() &#123;
		if (document.all && document.frmMain.cmdSubmit) 
&#123;
	document.frmMain.cmdSubmit.disabled = true;
	document.frmMain.cmdSubmit.value = 'Saving File...';
		&#125;
		if (submitDone == 0) &#123;
			submitDone = 1;
			return true;
		&#125;
		else &#123; 
			if (!document.frmMain.cmdSubmit || !document.all) &#123;
			alert("Saving File..."); 
			&#125;
			return false; 
		&#125;
	&#125;
//-->
</SCRIPT>
Then, example of use:

Code: Select all

<form action=example.php method=POST id="frmMain" name="frmMain" onSubmit="return preventDoublePosts();">
<input type=submit value="  Save Now  " id="cmdSubmit" name="cmdSubmit"></form>

Posted: Thu Apr 24, 2003 9:35 am
by k_nitin2k

Code: Select all

<?
echo"<SCRIPT LANGUAGE=javascript> 
<!-- 
function torf(a) 
&#123;
  if (a.element) &#123;
    return false;
  &#125;
  else &#123;
    return (a.element = true);
  &#125;
&#125;</SCRIPT>";

?>

<SCRIPT LANGUAGE= "javascript"> 
<!-- 
function wform(a) &#123;
  document.write('<form onSubmit= "return torf(this); " method="post" action=" '+a+' ">\n');
&#125;</SCRIPT>";

<SCRIPT LANGUAGE= "javascript"> 
<!--
function wsubmit(a) &#123;
  document.write('<input type="submit" name= "Submit" value= " '+a+' " class= "submit">\n');
&#125;
</SCRIPT>";

<script language="JavaScript">
wform( "test.php?usrid=<? echo $usernumber; ?>&rulername=<? echo $rulername; ?>&galaxypos=<? echo $galaxypos; ?>&systempos=<? echo $systempos; ?>&gamemode=<? echo $gamemode; ?>");
</script>

<script language="JavaScript">
wsubmit("Send Out Attack");
</script>