I would like to implement a multi-form submission prevention into my application, however I'm falied to do it.
I have tried different method, doing it with the Session method, but it does not work.
I actually want to insert data into the DB and send an email to a user. The process takes a little bit of time, like 1 second.
I have tried to create a token in a hidden field in my form, create a session for it too and regenerate it every time the page loads.
The problem is, that within the 1 second the visitor can click about 6-7 times to that button, and it will run the script over and over again.
I have tried to check if the Session equals to the hidden form's value, but they are the same each time, so it doesn't prevent the submission.
Is there any way that I can prevent this kind of vulneralibity?
EDIT:
What I've tried already has worked if I've reloaded the page, so they couldn't resubmit the form twice, but for some reasn it doesn't work, when it gets another request while the other is still being processed.
EDIT2 - Explaining the situation:
I have a file called: view.php. In here I have the form elements, including different textboxes and a submit button. The form type is POST and the action is set to default (submit on the same page).
I also have a file called: model.php. In here I'm doing the checking processes of the form submit.
I also have a file called: controller.php. In here I'm including the above files, so they are connected. First the model.php and at last the view.php.
So when someone clicks on the submit button in View.php, my model.php checks if the textboxes are not empty, etc. and gived back errors if there is a problem. When everything is okay, it allows the app to add the info to the DB and send an email to the user about the confirmation. After that the user gets redirected.
This is the whole process. I'd like to prevent multiple submit without JS and insert plus info to the DB.