在表单数据中错误输入时刷新页面

时间:2018-03-23 21:27:56

标签: php wordpress

所以,这是我的第一个问题,我为不是一个非常自信的编码器而道歉。 (不是我的主要职位......)

我们正在使用带有一些额外代码的Wordpress站点,使用PHP文件根据表单输入重定向站点移动。我们使用的一个例子如下:

<?php //Turn the content from text box into variable
$page=$_POST['text'];

if($_POST['text']=='sit') {
//set up a redirect to that page
echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://exampleurl.com/index.php/private/core\">";

}

else if($_POST['text']=='pony') {
//set up a redirect to that page
echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://exampleurl.com/index.php/private/ponytail\">";

}

它对我们来说非常好用,但是我被要求可能添加一些代码,如果一个人输入了一个不正确的术语,价值等,它不会只是循环到一个空白页面,而是刷新它所在的页面。

我们可以添加到这个php文件以获得所需的功能吗?

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

添加上一个else条件,如下所示。将http://exampleurl.com/index.php/调整到所需的页面。

<?php //Turn the content from text box into variable
$page=$_POST['text'];

if($_POST['text']=='sit') {
   //set up a redirect to that page
   echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://exampleurl.com/index.php/private/core\">";

}

else if($_POST['text']=='pony') {
   //set up a redirect to that page
   echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://exampleurl.com/index.php/private/ponytail\">";

} else {
   echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://exampleurl.com/index.php/">";
}
相关问题