【发布时间】:2013-04-22 20:43:43
【问题描述】:
我有一个 HTML 表单,提交后会转到一个 php 页面,该页面编写一个新 HTML,其中新 HTML 具有写入它的第一个 HTML 页面的值。
例如。在输入:文本中,我输入“hi”并点击提交。然后进入一个 php 页面,该页面创建新的 HTML,其中 input:text 具有 value="hi"
我在下面发布的代码有效,但我必须放置一个“虚拟”name="x" 才能被 value="myvalue" 替换。有没有办法将它添加到元素中而不是替换某些东西。
还有没有办法使用它来将值放入文本区域?
使用此问题的帮助:Printing the current page to pdf using wkhtmltopdf 我正在使用此代码:
$documentTemplate = file_get_contents ("form.html");
foreach ($_POST as $key => $postVar)
{
if($postVar == "on")
$documentTemplate = preg_replace ("/name=\"$key\"/", "checked", $documentTemplate);
else
$documentTemplate = preg_replace ("/name=\"$key\"/", "value=\"$postVar\"", $documentTemplate);
}
file_put_contents ("form_complete.html", $documentTemplate);
$html = file_get_contents("form_complete.html");
echo $html;
【问题讨论】:
-
执行此操作的常用方法是首先使用脚本创建表单,在提供时填写来自
$_POST的值,而不是使用静态 HTML 文件。
标签: php