tags:

views:

293

answers:

2

I have this html form which calls a php file .

The index.html ->

<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 html code and sends it to the client. But what I want is for the php(or anything else) to create a static html page , store it in the server and THEN send it to the user. I hope I am clear.

This is for a very small website for my neighbourhood btw and my coding skills suck bigtime Lastly if someone understands what I am trying to do and has a suggestion to do this in any other way(simpler way), then please share.

Thanks

+1  A: 

You would just open an file, print the HTML to the file (using puts or similar), close the file, then redirect the user to the new file using header("Location: ..");

As to general tips, I would just suggest reading up on "cleaning" or "sanitizing" user input.

Devin Ceartas
+2  A: 
<?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
?>
karim79
Thanks a lot that works!