I have 3 php files: request.php
, action.php
,mail.php
.
request.php
generates the page, filling it with different data depending on the POST
data sent by ajax. It starts as a form, with multiple fields. When you click the submit
button, ajax sends the form data to action.php
via POST
. action.php
then processes the data, storing it in the database, and generating an html div
that cleanly lays out the data. action.php
then uses html2canvas
and jsPDF
to to the html div
into a pdf, which then is passed to mail.php
via jquery POST
to be emailed out with phpmailer
. action.php
then generates a success message which is sent to request.php
and displayed.
However, the javascript inside action.php
that sends the pdf to mail.php
always fails to run. I've tried a variety of ways to do it, but I can't seem to figure out another way to pass all the data where it is needed, as the data needs to be passed twice: first as an array of raw data, then as a pdf generated by html2canvas
and jsPDF
.
If I place a hidden iframe
of mail.php
inside action.php
it will run fine and send the email, but it will be an empty pdf not filled with any of the data from request.php
(obviously).
I can think of a few potential solutions but I cannot figure out how to implement them:
1) It seems the issue is that javascript doesn't like to run nested, but perhaps there is a way to force the javascript code inside action.php
to run so that the pdf is generated and sent to mail.php
.
2) Maybe there is a way to do it all with only one data pass that I am not seeing.
3) Maybe there is a way while inside action.php
to pass the data array to an iframe
for process.php
which would format the html div and generate the pdf and then send it off to mail.php
, but I assume even if I could get that done I would run into the same problem of the javascript in process.php
failing to run and send the pdf to mail.php
.