Disable double click on Save

dimoss

Well-Known Member
Hi

I would like to know how is it possible to disable the double click on Save in order to avoid adding the same record twice in the db.

I have found the following code in Javascript but I don't know how to implemented it into my form:

Code:
<input type="submit" name="Save" value="Save" onclick="this.disabled=true; this.value='Please Wait...';" />

The problem is that even I have put an areuniquevalues validation on an element which work very good in normal situations, in some very very rare and extreme double clicks the validation passes (I don't know how!) I get the same record twice on the db table. I don't know how it happens but it happened at least two times with exactly the same creation datetime!

Any comments on this are very much appreciated!

Thanks
 
Is this form by any chance completing a user registration via Fabrik?
I found that if you disable "Create Account" in the User manager for Joomla (Options > Allow User Registration = No) then create the account in Joomla you get duplicate entries of your Users and of records you add to your list. This maybe what is happening rather than double click?
I have tried double clicking submit on my apps and cant seem to replicate your problem.

To prevent people creating an account via Joomla I overrode the mod_login >tmpl > default.php file


Code:
<?php
            $usersConfig = JComponentHelper::getParams('com_users'); ?>
            <ul class="unstyled">
            <?php if ($usersConfig->get('allowUserRegistration')) : ?>
                <li>
                    <a href="<?php //echo JRoute::_('index.php?option=com_users&view=registration&Itemid=' . UsersHelperRoute::getRegistrationRoute()); ?>">
                    <?php //echo JText::_('MOD_LOGIN_REGISTER'); ?> <!--<span class="icon-arrow-right"></span></a>-->
                </li>
            <?php endif; ?>
 
Hi

Thanks for the reply however the form is not used for user registration.
It's just a simple form where i would like to lock (disable) somehow the double clicking preventing the same record created twice.
 
Hi Troester

Is this setting used to disable the double posting somehow?
Because I see the loading but i don't know if this works on speedy double clicks.
I know it's strange but it happened twice!
Thanks.
 
You could trying hanging an event handler on fabrik.form.submit.start, in a form_X.js file, like ...

Code:
Fabrik.addEvent('fabrik.form.submit.start', function(form, ev, btn) {
   btn.disabled - true;
});

... or some such. Basically, we fire off that event when we start the submission handling, and pass it the form, event and button objects as args. I'm not 100% sure that the btn would be the DOM element you would set the disabled attribute on, but you should be able to throw a breakpoint on that line, inspect the btn variable, and work out where to go from there.

-- hugh
 
However ... I'm not 100% convinced that double clicking is the issue, as I would have thought our submission broker would prevent double submissions, although I could be wrong. Basically, we already have some code which *should* prevent a form being submitted again, once the doSubmit() function has already been called, unless the form specifically allows it - we added that to handle aborting submits if AJAX file uploads haven't been handled yet, and some other cases where we want to abort submission, and not allow double submits.

But ... give it a go anyway.

If you are insatiably curious, look at the start of doSubmit in media/com_fabrik/js/form.js, around ine 1040, and you'll see how we check the state of the submission broker, and abort if it's already enabled, and if not, we enable it. Although I guess it's possible two async button click events could come through in such quick succession that the broker didn't have time to complete before the second call came in. But in that case, I doubt an event handler would have any more success ... unless we eventually worked out how to make our events syncronously blocking instead of async, which we may have done ... I lost track a while back ...

-- hugh
 
Bottom line, I think that occasionally, form submissions get handled twice on the server side ... something goes wonky deep down within the TCP layer itself, and the httpd winds up pocessing the same submission twice. But that's just a pet theory ... although I did spent endless hours trying to debug some similar issues on a very small form 9small enough so it would be contained in one low level network frame) on my own test server a year or so ago, after a couple of people reported similar issues.

I even set up a packet sniffer, and could never see any evidence of double transmission across the wire, as one wuld expect to see if the browser actually submitted twice, even when a form fot processed twice. Which is why IMHO it's happening deep within the server's TCP stack and/or httpd code.

-- hugh
 
Second bottom line ... if this is mission critical, you may be better off writing a quick scheduled task to check for duplicate entries, and have it warn you about them, so you can deal with them by hand.

-- hugh
 
Hi Hugh

Thanks a lot for your detailed answer :)
Thanks twice because you are on recovery and you took the time to reply.
I hope you will be back soon with a bionic neck!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top