使用PHP 5.6.27我试图通过组合
生成HTML文件(1)来自表单字段的输入
(2)HTML代码(模板)
问题:文件已创建,但只有$ template值,但没有表单字段输入。
代码如下。此处的实时链接位于http://fastlaw.in/formv2.html
当然,我错过了一些简单的事情,但如果有人能提供帮助,我会很感激。
formv2.html
<form action="formscriptv2.php" method="POST">
<input id="field1" type="text"/> <br />
<input id="field2" type="text" /> <br />
<input type="submit" name="submit" value="Save Data">
</form>
formscriptv2.php
<?php
$Field1 = $_POST['field1'];
$Field2 = $_POST['field2'];
$onepart = "
<div class='table table-left'>
<section>
<h2 class='table-heading'>";
$twopart = "</h2>
<table class='data'>
<caption>
<p>";
$threepart = "</p>
</caption>
";
$template = $onepart . $Field1 . $twopart . $Field2 . $threepart;
$ret = file_put_contents('tmp/mydata.txt', $template, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
?>
答案 0 :(得分:1)
PHP $_POST
数组通过name
HTML属性填充:
<input id="field1" name="field1" type="text"/> <br />
<input id="field2" name="field2" type="text" /> <br />