I am trying to use the php output buffering function to create a new html page after a user form submit.
I researched this here, and found help with this answer on another thread.... https://stackoverflow.com/a/3775302/7637995.
That advice did work for me to produce an html page to my server.
However, I need to take it a step further and so far, haven't found a way to do that.
As I stated... with the code provided in that answer, and embedded in my PHP page... I was able to generate a new html page, with all of my form data intact on my server, by setting the 'name' of the html page to "Mydocument" like so...
<?php ob_start(); ?>
/* My 'Form Page' Content Here */
<?php echo '';
file_put_contents('Mydocument.html', ob_get_contents());
?>.
However... instead of having to name a 'one-off' destination html page in advance, by hard-coding it in each time... I would like to know if it's possible to have the form itself, automatically generate a name for a new destination html page each time the form is submitted. Perhaps based on the input data from one of the text form fields.
In the form, for example... I have a field named 'banner'. The text entered into that field eventually becomes the headline for an article on the html page.
So... I was wondering if the data in that 'banner' field, could also be used to automatically generate a 'name' for the destination html page.
Therefore, instead of me having to code a 'name' for the destination html page, such as; 'Mydocument.html' (or whatever)... the form would automatically create a name for that html page itself on submit.
For example... if my headline (entered into the 'banner' field of the form) is
"Giant Asteroid To Hit Earth"
By the time the PHP code generates, it may look something like this....
<?php ob_start(); ?>
/* My 'Form Page' Content Here */
<?php echo '';
file_put_contents('Giant%Asteroid%To%Hit%Earth.html'
, ob_get_contents());
?>.
If anyone can help me with this... it would be much appreciated.
<?php
ob_start();
$headline=str_replace('.', '_', basename($_REQUEST['banner']));
?>
/* My 'Form Page' Content Here */
<?php echo '';
file_put_contents($headline . '.html'
, ob_get_contents());
A couple of things you should note here: the basename function fixes a whole lot of security issues. And I've removed the redundant closing '?>'