【发布时间】:2018-10-20 05:44:15
【问题描述】:
实际上我需要在同一个php页面中回显表单并获取表单数据或发送到另一个php页面,因为我无法在这里发布我的原始代码,所以准备了伪代码。
<?php echo "<html><body>";
if(isset($_POST['submit']))
{
$name = $_POST['firstname'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
}
echo"<form action=$_SERVER['PHP_SELF']>
First name:<br>
<input type='text' name='firstname' value='John'><br>
Last name:<br>
<input type='text' name='lastname' value='Rambo'><br><br>
<input type='submit' value='Submit'>
</form></body></html>";
?>
php页面被调用/加载成功加载。表单也在工作。但是
form action=$_SERVER['PHP_SELF'] 不起作用,下面的代码也不起作用。
if(isset($_POST['submit']))
{
$name = $_POST['firstname'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
}
【问题讨论】:
-
将
<input type='submit' value='Submit'>更改为<input type='submit' name='submit'> -
更改 -
<form action=$_SERVER['PHP_SELF']>- 到<form action='{$_SERVER['PHP_SELF']}' method="post">