...

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



blumonde
07-20-2012, 08:18 PM
Hello,

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:

<?php
ob_start();

$hearingform = '
<html>
<head>

<style type="text/css">
.....
</style>

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

<script type="text/javascript">

function FreezeScreen(msg) {
scroll(0,0);
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;

exit;
} //END post IF

print $hearingform;

ob_flush();
?>

Old Pedant
07-20-2012, 08:38 PM
http://aspmessageboard.com/showthread.php?235845-Need-help-with-quot-Prevent-Users-from-Submitting-a-Form-Twice-quot

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.

WolfShade
07-20-2012, 09: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.

felgall
07-21-2012, 04: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, 04: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum