#1
  1. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,146
    Rep Power
    144

    stop multiple button press


    Hi--

    I've got a very large form where people click buttons to sign up for classes. There can be 100 classes and 100 buttons at any one time.

    One problem I'm running into -- sporadically -- is clients will push a button 3 times in 1 second and end up registering for one class three times despite my safeguards.

    One safeguard is:

    Code:
    $("*").dblclick(function(e) {
    			 	e.preventDefault();
    			 });
    The buttons run some AJAX to a PHP script that saves the class to the database. That script also verifies the client is NOT already scheduled for the class before scheduling it.

    Well, it seems you can't make something totally foolproof. I track all the user interactions and this particular user did press the button 3 times and sign up for the class 3 times in one second despite my failsafes.

    Any ideas on this?

    Thank you!

    EDIT: I just learned this client is using an iphone to interact with the form. Is it possible iOS doesn't like my JS function above?
    Last edited by Frank Grimes; April 15th, 2017 at 07:27 PM.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Location
    Jakarta, Indonesia.
    Posts
    279
    Rep Power
    37
    Hi,
    As far as I could remember there is this disabled attribute for a button,
    which may be set via javascript, e.g:

    Code:
    $(this).find('[type="submit"]').attr('disabled', true);
    when sending an ajax, and

    Code:
    $(this).find('[type="submit"]').attr('disabled', false);
    on ajax receive event arrival?
  4. #3
  5. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,146
    Rep Power
    144
    Originally Posted by hdewantara
    Hi,
    As far as I could remember there is this disabled attribute for a button,
    which may be set via javascript, e.g:

    Code:
    $(this).find('[type="submit"]').attr('disabled', true);
    when sending an ajax, and

    Code:
    $(this).find('[type="submit"]').attr('disabled', false);
    on ajax receive event arrival?


    Thanks for this. I'm actually removing the buttons from the DOM after they're pressed. But that's all Javascript. I'm wondering if the iphone is somehow caching these events and running them at once for some reason. I don't know.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    102
    Rep Power
    65
    Your database needs to enforce uniqueness. Whatever fields uniquely define one instance of a user/class need to be a defined as a composite unique index.

    To 'verifies the client is NOT already scheduled for the class before scheduling it', you would just attempt to insert the data, then detect any duplicate key error. If you first try to SELECT the data to decide to insert it or not, multiple concurrent submissions can find that the data doesn't exist and still try to insert the data.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Location
    Lakewood, WA
    Posts
    218
    Rep Power
    17
    Your database needs to enforce uniqueness.
    And the code needs error handling functionality such that enforced DB uniqueness doesn't just result in the appearance of everything is Kosher to the user, perhaps a popup that says "Hey, moron, can you read? It says clicky clicky ONCE!"

    I'm quite amused when I see the statement "Click only once!" on bill-pay / credit card forms, because it implies to me that there is a lack of code on the back-end that prevents garbage in from multiple clicks, which to me is simply mind-blowing.
    Last edited by Arty Zifferelli; April 23rd, 2017 at 07:36 PM.
  10. #6
  11. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,146
    Rep Power
    144
    Edit: never mind. Sorry to bother.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence

IMN logo majestic logo threadwatch logo seochat tools logo