-2

如何在提交后使 Html 表单消失并显示按钮以使表单再次出现并清除结果?

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
    echo "<br>You can use the following form again to enter a new name.";
}
?>
<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>
4

3 回答 3

0

注意:在else条件中包装 html

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
    echo "<br>You can use the following form again to enter a new name.";
}
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 }?>
于 2013-02-22T09:52:25.850 回答
0

你只需要插入你的整个form内部else部分

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
    echo "<br>You can use the following form again to enter a new name.";
    echo "<a href='your_page.php'> Page</a>";
} 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>
<?ph } ?>
于 2013-02-22T09:52:28.230 回答
0
<form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="name"><br>
    <input type="submit" name="submit" value="Submit Form" onclick="document.getElementById('myform').style.display='none'"><br>
</form>
于 2013-02-22T09:52:51.673 回答