Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need help with "Prevent Users from Submitting a Form Twice"

    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();
    ?>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,639 Times in 4,601 Posts
    http://aspmessageboard.com/showthrea...orm-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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,639 Times in 4,601 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •