Generating static html page using html form input
I have this html form that calls a php file.
Html index →
<form action="html_form_submit.php" method="post">
<textarea name="name" rows="2" cols="20"> </textarea >
<input type="submit" value="Submit" />
</form>
from html_form_submit.php ->
<?php
$name = @$_POST['name'];
?>
<html>
<body>
<p>
Id: <?php echo $id; ?><br>
Name: <?php echo $name; ?><br>
Email: <?php echo $email; ?>
</p>
</body>
</html>
This works as expected. The php file generates the html code and sends it to the client. But I want php (or whatever) to create a static html page, save it to the server and THEN send it to the user. I hope I get it.
This is for a very small website for my community and my coding skills suck bigtime Finally, if anyone understands what I am trying to do and you have a suggestion to do it some other way (easier way) please divide.
thank
+2
source to share
2 answers
<?php
ob_start(); // start trapping output
$name = @$_POST['name'];
?>
<html>
<body>
<p>
Id: <?php echo $id; ?><br>
Name: <?php echo $name; ?><br>
Email: <?php echo $email; ?>
</p>
</body>
</html>
<?php
$output = ob_get_contents(); // get contents of trapped output
//write to file, e.g.
$newfile="output.txt";
$file = fopen ($newfile, "w");
fwrite($file, $output);
fclose ($file);
ob_end_clean(); // discard trapped output and stop trapping
?>
+5
source to share