1

I'm not sure what to even be searching for here, so I'll explain what I am attempting to do.

I current have a form (several dropdowns, input fields..etc) When the form is submitted, I am currently generating an 'output page' for print that has all user entered data on the initial form state.. with a 'print document' button at the bottom.

In which the end user would print out and write in any custom/specific comments..etc..

The above all works as intended.

However.. there has been a change in direction.. and instead of printing it out. (and hand writing any custom/unique comments by hand)..

...they want to be able to 'DOWNLOAD' the output/display page as a .html file

(so I'd need to make all assets in-file..etc. like styles, and probably based64 encode any/all images..etc)

As I have never done this before.. I'm not even surer what Im look for?

Should this be a separate (physical) .html file? (how do I get the submitted data/values into it before downloading?)

Should is just be a huge 'string' that I pull in the post values into?

But once that is complete.. how do I prompt the user to save it as a downloadable .html file?

whispers
  • 962
  • 1
  • 22
  • 48
  • two options, refactor to put everything into a massive string, OR, use something like `wkhtmltopdf`, see here https://delboy1978uk.wordpress.com/2014/11/24/html-to-pdf-using-wkhtmltopdf/ – delboy1978uk May 04 '18 at 15:16
  • Maybe you can use PHP's header function to offer output for downloading without creating a file – Daniel Faure May 04 '18 at 15:25
  • Thanks... saving to .pdf is NOT an option.. (unless it can be an editable pdf where you can enter data into fields?) @Daniel Faure Is there an example of this or something? – whispers May 04 '18 at 15:32
  • @whispers, I wroted it down in an answer. – Daniel Faure May 04 '18 at 16:13

2 Answers2

1

Suppose you have your $html_string handling the contents of the page you want to download. It will be usefull to include CSS references.

<?php    
    $html_string.="<h1>This is your form</h1>";
    foreach ($_POST as $p=>$value) $html_string.="{$p} has {$value}";

    header('Content-Disposition: attachment; filename="readme.html"');
    // other header() calls you need
    die($html_string);    
?>

This should work.

Daniel Faure
  • 391
  • 6
  • 14
0

You could use "download" atribute in "a" html tag:

<a href="http://example.com/some.html" download>Download</a> 

Unfortunately this feature is not supported by IE browser.

Emeeus
  • 5,072
  • 2
  • 25
  • 37
  • Interesting to know. Not really an option here since its not widely supported, but still good to know. (not even sure how that works?) or how you would pass in dynamic values/data to it before the 'download/saving'? – whispers May 04 '18 at 15:33
  • You could generate the .html when you want (ajax + php), and show the download buttom when you want too (callback from ajax). So you could generate the file when the user fill out the form, when the file is created then you show the download button. – Emeeus May 04 '18 at 15:45