将变量从输入传递到表单

时间:2013-10-19 13:53:04

标签: php

如何将输入字段中的变量传递给这样的形式,是否可能?

<form method="POST" action="https://accounts.google.com/o/oauth2/auth?login_hint=<?= $_GET['email']?>" id= "frmTest" name = "frmTest">
   <input type="email" id="email" name="email"  />
   <input type="submit" id="submit" name="submit" />
</form>

或者也许以某种方式使用javascript? 当用户填写该表单并单击“提交”按钮时,我希望该表单将其重定向到 https://accounts.google.com/它将显示该电子邮件,用户只需输入密码

3 个答案:

答案 0 :(得分:3)

我认为我看到了解决方案。您通过POST方法发送数据,但期望它们位于$ _GET变量中。在您的代码中将方法之一(POST / GET)更改为另一个方法。

答案 1 :(得分:2)

您可以将其添加到隐藏的输入中,如下所示:

  <input type=hidden name=login_hint value="<?php echo $_GET['email'] ?>" >

答案 2 :(得分:2)

如果您在表单中使用POST方法,则无法在GET属性中添加action查询参数。

POST形式,action网址中的这些参数将被丢弃。因此,请将您的表单发送为GETmethod="GET")并保持查询字符串不变,或将其保留为POST并在隐藏的输入中添加字段,如:

<form method="POST" action="https://accounts.google.com/o/oauth2/auth" id="frmTest" name="frmTest">
  <input type="hidden" name="login_hint" value="<?php echo $_GET['email']; ?>" />
  <input type="submit" id="submit" name="submit" />
</form>