I have a simple acceptance form that has a single button that the user clicks. On form submit, I have a php script that makes a command line call to a python script that adds records to my database. All works great besides one thing: I don't want the user to be able to click the button more than once.
- If I disable the button using javascript, my if (isset($_POST['submit'])) statement doesn't evaluate to true and then my php doesn't run
- If I call a javascript function within the php script, the user still has an opportunity to click the button multiple times before the php script calls the function to disable the button. This allows them to make multiple records in my db.
My idea was to have my python script, which is the one adding records, first check if a record with the same information already exists in the db and only create a new one if not. My concern is that if the user clicks the submit button multiple times, it could be that multiple php will execute multiple calls and the second one will check if a record is already created before the first call creates a new record.
In other words, maybe the php calls will work at the same time (asyncronously?) and checking the database won't cover for another call creating a record at the same time. Is this a valid concern?
Are there other ideas of how I could disable or hide my button but still have my php script run? Thank you.
For future viewers, the workaround I ended up using is based on what Teemu said in the comments below. Before adding a new record from the form submission to the db, I checked if a record already existed with that information. If not, I added a record, if so the button click did nothing. As Teemu mentioned, this check would be necessary anyway to cover for multiple submissions that could be posted even without the button on the page. This is what I call a "workaround" and not an answer because the user can still click the submit button multiple times but only the first click has an effect. The button then hides itself after the php has finished running.