<?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>
我只想在提交后运行部分,并且在点击提交表单按钮后不会看到显示表单
答案 0 :(得分:6)
将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 } ?>
答案 1 :(得分:1)
使用exit。
if(isset($_POST['submit']) {
$name = $_POST['name'];
echo "User has submitted the form and entered this name : <b> $name </b>";
exit;
}