I am junior PHP dev and I am currently working on making a quote form which will take customer details and whatever the employee enters in the quote form and will:
- Save customer and quote detail to DB.
- Generate a PDF (using mpdf library)
- Email the pdf to the customer
Currently its just two files index.php and quote.php
Here is a diagram
As you can see it is a monolithic architecture (I have all the operation in one PHP file).
This is causing problems as when the user hits "SUBMIT" and quote.php does all its functions , the user is stuck on that page. Then if they hit Refresh , quote.php will be re-executed again and it ends up spamming my database tables, and email inbox.
I was wondering what is the best way to prevent the user from re-executing or going back to doing stuff which should only be done once.
I had a couple of ideas and was hoping you could suggest me yours?
Idea 1: A session variable that prevents re-execution of the same code.
Idea 2: Break up the quote.php file into seperate files and jump from each one. (is this possible)?
I want to do this the best way possible and I am open to any suggestions!
Thankyou for your time!
:)