I have a need have my entire page's HTML passed into a PHP variable, but I have no idea if this is even possible or if it will accomplish what I'm trying to do.
The idea is that the user would click a button (PRINT) and the script would gather the entire HTML of the page and POST it to a PHP file. The PHP file is generating a PDF using a third party service (DocRaptor).
Any thoughts on the best way to do this? Would it even work?
EDIT Some code since you asked. This is as far as I get. This works and I get a PDF of the text submitted in the text input box. But that's obviously not what I need. I'm just not sure how to POST something that not the text input, but rather the entire current HTML of the page. It doesn't have to be a form obviously, a button (Print Page) would be ideal.
HTML:
<form method="POST" action="print_submit.php">
Innovation Name<input type="text" name="this_data">
<input type="submit" value="Sumbit my choice"/>
</form>
PHP (print_submit.php):
<?php
$api_key = "XXXXXX";
$url = "https://docraptor.com/docs?user_credentials=$api_key";
$content = $_POST['this_data'];
$name = 'docraptor_sample.pdf';
$post_array = array(
'doc[name]' => $name,
'doc[document_type]' => 'pdf',
'doc[test]' => 'true',
'doc[document_content]' => $content
);
$postdata = http_build_query($post_array);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$doc = file_get_contents($url, false, $context);
file_put_contents($name, $doc);
?>
Here is a link to your pdf: <a href="<?=$name ?>"><?=$name ?></a>