PHP - 在提交按钮上更改整个页面内容

时间:2012-08-14 14:08:47

标签: php html

我有两个php页面index.php和page2.php 我希望当我第一次加载网站时会显示index.php,里面有一个搜索按钮。单击提交按钮我要显​​示page2.php的全部内容(现在我只在page2.php上显示)在index.php上,删除了对page2.php的需求。

2 个答案:

答案 0 :(得分:1)

更改您的表单,以便重新加载相同的页面:

<form method="post">
    // inputs go here
    <input type="submit" value="Submit" name="submit" />
</form>

然后包含一个if语句,用于检查表单是否已提交:

if (isset($_POST["submit"])){ // form already submitted
    // echo page2.php code here or simply include the code from an external file
}
else {
    // echo the form code above and anything else from the first page here
}

答案 1 :(得分:0)

从page2.php复制脚本并将其从index.php中删除? 在这个闭包中:

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
//
}
?>