View Full Version : Need help with "Prevent Users from Submitting a Form Twice"

07-20-2012, 09:18 PM

I read an article on "how to prevent users from submitting a form twice." at the url http://www.4guysfromrolla.com/webtech/100406-1.shtml

I was able to freeze the web page but was not able to unfreeze the web page. I am using PHP with javascript. Nothing happens when my code executes the "unfreeze" js function. I tested this js function and it only worked after I disabled the 2 php header() functions below. The JS unfreeze function just stops working with the php header functions enabled. There were no errors. Only the web page still freezes.

I hope someone can give me advice to help me solve this issue. Thanks in advance.

Below is my code in short version:


$hearingform = '

<style type="text/css">

<div align="center" id="FreezePane" class="FreezePaneOff">
<div id="InnerFreezePane" class="InnerFreezePane"> </div>

<script type="text/javascript">

function FreezeScreen(msg) {
var outerPane = document.getElementById("FreezePane");
var innerPane = document.getElementById("InnerFreezePane");
if (outerPane) outerPane.className = "FreezePaneOn";
if (innerPane) innerPane.innerHTML = msg;

function unFreezeScreen() {
var outerPane = document.getElementById("FreezePane");
outerPane.className = "FreezePaneOff";

// some code to pull data from the database here...

// unfreeze the webpage
echo '<script type="text/javascript">unFreezeScreen();</script>';

/*send data to an excel file*/
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=$filename");

echo $data;

} //END post IF

print $hearingform;


Old Pedant
07-20-2012, 09:38 PM

But looking at this again and closer...

I don't think it makes any sense.

You have PHP code embedded inside JavaScript code. That's not legal.

Maybe you need to show the page live? Your "short version" code is just nonsense.

07-20-2012, 10:29 PM
Part of the problem (perhaps?) is that you are using PHP to echo the JS command to unfreeze BEFORE printing the variable that contains your JS/HTML.

Personally, I've never understood why anyone would want to use a dynamic server-side language (or JavaScript) to "write" HTML. Just write the HTML and use the server-side language for more important things. Just MHO.

07-21-2012, 05:11 AM
A better solution would be to test server side if the same form has been submitted twice. That way you perform the test for everyone and not just those with JavaScript enabled.

Old Pedant
07-21-2012, 05:26 AM
The article in question was addressing the problem of pages with a slow response time, such that users would hit the submit button multiple times.

In addition to preventing multiple submissions, it gave a visual indication that the page had been submitted.

So it's a nice feature, though you are right about ALSO wanting to do the check server-side.