我正在我的网站上创建一个脚本来回显整个表单的内容。我的HTML代码如下所示:
<form action ="forma.php" method ="POST" name="FORM-TXT">
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
<input type="submit" name="submitsave" value ="Submit">
</form>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//use the html Name element to attach html to php scripts
//V-----------------=|txt file codes|=-----------------V
$text = $_POST["FORM-TXT"];
echo $text;
?>
当我运行表单时,抛出此错误:
注意:未定义的索引:FORM-TXT in 第7行/homepages/31/d585123241/htdocs/mail/forma.php
我怎样才能使整个表格回声,但没有引用任何特定元素,只有表格。
答案 0 :(得分:0)
喜欢@EatPeanutButter说
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//use the html Name element to attach html to php scripts
//V-----------------=|txt file codes|=-----------------V
$text = $_POST;
var_dump($text);
?>
答案 1 :(得分:0)
您无法以这种方式打印HTML。但是,您可以执行以下两项操作之一:
1)将整个HTML字符串转换为变量,如下所示:
$form = <<<HTML
<form action ="forma.php" method ="POST" name="FORM-TXT">
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
<input type="submit" name="submitsave" value ="Submit">
</form>
HTML;
echo $form;
另一种方法是简单地在你的逻辑之后关闭php标签,表格将自动显示:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//use the html Name element to attach html to php scripts
//V-----------------=|txt file codes|=-----------------V
?>
<form action ="forma.php" method ="POST" name="FORM-TXT">
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
<input type="submit" name="submitsave" value ="Submit">
</form>