I have a HTML form that when submitted it goes to a php page which writes a new HTML where the new HTML has the values of the first HTML page written to it.
Ex. In a input:text I put "hi" and hit submit. This then goes to a php page which creates the new HTML where that input:text has value="hi"
The code I have posted below works but I have to put a "dummy" name="x" to get replaced by the value="myvalue". Is there a way to just add this to the element instead of replacing something.
Also is there a way to use this to put the value into a textarea?
Using help from this question: Printing the current page to pdf using wkhtmltopdf I am using this code:
$documentTemplate = file_get_contents ("form.html");
foreach ($_POST as $key => $postVar)
{
if($postVar == "on")
$documentTemplate = preg_replace ("/name=\"$key\"/", "checked", $documentTemplate);
else
$documentTemplate = preg_replace ("/name=\"$key\"/", "value=\"$postVar\"", $documentTemplate);
}
file_put_contents ("form_complete.html", $documentTemplate);
$html = file_get_contents("form_complete.html");
echo $html;