2012-04-26 110 views
0

我为使用Indexhibit或Wordpress的客户做了几个网站。我一直得到相同的'我在哪里登录?'来自他们的电子邮件,因此想要在我的网站上创建一个简单的转发表单,客户可以在其中输入URL,选择Wordpress/Indexhibit并单击转到并转发到该网站。简单的PHP表单重定向

我已经建造了一些谷歌上搜索后执行以下操作:

<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $siteid1 = $_POST['siteid1'];    header('Location: http://' . $siteid1 . '/ndxz-studio/'); else:?> 
<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post"> 
<h3>Indexhibit</h3> 
<p class='formp'>If your website is powered by <em>Indexhibit</em> submit your URL to be forwarded to your admin area</p> 
<input input class='loginforms' type="text" value='i.e. your-domain-name.com' onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'i.e. your-domain-name.com':this.value;" name="siteid1" /> 
<input class="btn btn-success loginbuttons" type="submit" value="Go" /> 
</form> 
<?php endif; ?> 

然后再次以相同直接在它下面的WordPress的。

但是因为我使用

<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $siteid1 = $_POST['siteid1'];    header('Location: http://' . $siteid1 . '/ndxz-studio/'); else:?> 

似乎只需要接受本网站上的一种形式。 (所以要么indexhibit无法去/ ndxz工作室或WP未能去可湿性粉剂管理员)

PHP是不是我的专长所以道歉,我已经犯下任何愚蠢的错误

回答

3

这是因为这一点:

<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $siteid1 = $_POST['siteid1']; 

这在您的表单中总是如此。所以,PHP执行它。 PHP从来没有达到第二个if声明,所以它永远不会执行。

尝试的if else声明,并确保你的表单名称是唯一

编辑:

这里是一些示例代码,让你开始。

if($_POST['siteid1']) { 
    $siteid1 = $_POST['siteid1']; 
    // execute code here 
} elseif($_POST['siteid2']) { 
    $siteid1 = $_POST['siteid1']; 
    // Execute code here 
} 
+0

这就是我所苦苦挣扎的。如果表单是分开的,我如何构造IF语句? – tjh 2012-04-26 18:45:49

+0

查看上面的示例。基本上你正在检测哪个'$ _POST'被设置。基于此,您将执行适当的代码。 – 2012-04-26 18:52:34

+0

这是一个链接到文档进一步澄清... http://us3.php.net/manual/en/control-structures.elseif.php – 2012-04-26 18:53:30