想要仅在单击提交按钮时显示页面

时间:2017-02-13 13:10:37

标签: php forms session-variables

嗨朋友们有2个文件index.php,form.php。在index.php中,我将index.php中的表单操作作为form.php。如果用户在浏览器url中输入example.com/form.php,如何显示如何隐藏它

如何在index.php上单击按钮时如何显示form.php?

1 个答案:

答案 0 :(得分:1)

设置sessions并检查是否为真,然后让form.php在索引页面上运行其他重定向,或者只能在一个页面中合并您的表单

<?php

if (isset($_POST['submit']))
{

//if button clicked run this php

//your php code here...


} else { 
//if button not clicked show form
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" name="myform">

//form fields here...

<input type="submit" name="submit" value="submit">

</form>

<?php } ?>

如果点击按钮,它将执行php代码,否则只显示表单

相关问题