当我使用action ="practice.php"时,它将打开一个空白网页,其中包含practice.php文件所在的目录。
<form method="post" action = "practice.php">
<-- <input> here -->
Person's Name: <input name="personname" type="text" /> </br>
Person's Name: <input name="personname" type="text" /> </br>
<input type = "submit" value = "Submit"/>
</form>发布于 2013-12-30 02:41:32
你可以使用redirect,在practice.php中有一个header('Location: someotherpage');来做重定向。
发布于 2013-12-30 02:59:24
你似乎问了两个截然不同的问题。我将回答你题目中的问题。
使用header()函数,并将" location“属性设置为要重定向到的位置。在下面的示例中,我在HTML脚本前面添加了一个PHP脚本。该脚本只是转储$_POST的内容,无论$_POST包含什么,都会发生转储,然后检查$_POST中的"personname“数组。如果"personname“存在,它将重定向到"Location: /newpage.php”。
如果愿意,您可以在重定向之前执行一些其他处理,而不是仅转储$_POST的内容。
我还更改了input元素的"name“属性,以便将多个"personname”值以数组的形式传递给PHP,而不是仅以标量变量的形式传递最后一个值。
我还将"<-- here-->“更改为"”。看起来你是想对此发表评论。
<?php
var_dump($_POST);
if ( $_POST['personname'] > '' ) {
header("Location: /newpage.php");
}
?>
<form method="post" action = "practice.php">
<!-- <input> here -->
Person's Name: <input name="personname[]" type="text" /> </br>
Person's Name: <input name="personname[]" type="text" /> </br>
<input type = "submit" value = "Submit"/>
</form>https://stackoverflow.com/questions/20828676
复制相似问题