From what I have so far, I have an HTML form using method POST for PHP. What I want to do is automatically create a page using the input that includes a stylesheet and things that aren't in the form. I know that it is possible to create an XML page like this, as I have, but can you make an HTML page? Here is what I have so far, including the creation of the XML page and is creating an HTML page much like creating an XML page?
HTML form:
<form action="insertpage.php" method="post" class="form">
Noun<input name="form1" value="" type="text">
Adjective<textarea name="form2" cols="40" rows="4"></textarea>
<input type="submit" value="Submit">
</form>
PHP creating XML file
$xml = new DOMDocument("1.0");
$root = $xml->createElement ('root');
$xml->appendChild($root);
$form1 = $xml->createElement ('form1');
$vtext = $xml->createTextNode($_POST[form1]);
$form1->appendChild($vtext);
$root->appendChild ($form1);
$form2 = $xml->createElement ('form2');
$advtext = $xml->createTextNode($_POST[form2]);
$form2->appendChild($advtext);
$root->appendChild ($form2);
$xml ->save("words/$_POST[form1].xml"))) or die ("error creating file");
This works perfectly fine, except I cannot find a way to automatically create an HTML page with the user input. Is there any way to do this with PHP because that would be perfect too. By the way, I know this method is terribly unsafe, and I am working on creating some security like captcha. Also if you can't do this with PHP, is there any other programming language that can do this? Thank you
Here's a pretty simple idea to get you started.
HTML Template: template.html (Very much trimmed down)
<div>
<p>[[name]]</p>
<p>[[email]]</p>
</div>
HTML Form:
<form action="whatever.php" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email address" />
<button>Create Page</button>
<input type="hidden" name="create_page" value="true" />
</form>
PHP Script:
<?php
if (isset($_POST['create_page']))
{
$template = file_get_contents('template.html');
$template_vars = array(
'name' => $_POST['name'],
'email' => $_POST['email']
);
foreach ($template_vars as $k => $v)
{
$template = str_replace("[[{$k}]]", $v, $template);
}
file_put_contents('newfilename.html', $template);
}
Hope that helps.
It's worth mentioning that this is open to malicious user input, you should sanitize all the post data, this is just a very quick example.
只需将<?php echo $_POST['form1'];... ?>
标记与<input>
一起使用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.