<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>
我只希望部分在提交后运行,并且在单击提交表单按钮后不应看到显示表单
最佳答案
在 else 部分编写您的 html 表单代码。
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
} else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>
<?php } ?>
关于PHP_SELF 调用同一文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14451914/