I’m working on a form in which you can order courier service. The main idea for it is to generate PDF file containing validated data and then attach it to an e-mail to client + cc for courier company.
The thing is pdf generation (TCPDF) and e-mail sending (Swiftmail) takes noticeably long.
I would like to prevent impatient user from clicking ‘confirm’ over and over. The ideal solution would be to show some gif ‘loading’ image or so. I’ve looked into jquery .load() function and it looks like a good thing for this problem, but what about users w/o js?
Can you point me in the right direction?
I would use ajax in this case. but if lack of JS is a genuine concern for you, there are couple of ways to do this without JS.
First you can display something to the user before starting to work with pdf. eg
function flush() will force the webserver to send the data to the browser, so it will be displayed while the rest of the page is loaded. However some browsers will cache this thing internally. There are ways to overcome this (check out comments in php.net for a flush() function) but it could get messy.
Another way is to process PDF asynchronously. In this case target script just displays a message that email will be send shortly. And fires the script witch actually going to send it. eg:
in this example “process_pdf.php” will get all the same POST parameters as original script. but will be executed in the background without interrupting the original page.