未发送表单请求的参数

时间:2018-03-09 16:15:43

标签: html forms

我对此表单有疑问,无论我使用哪种方法(POST或GET),它都不会发送请求参数emailpass

<!DOCTYPE html>
<html>
<body>
    <form action="controller/connect_user.php" method="GET">
        <label for="email">Email:</label>
        <input type="email" id="email" required>
        <label for="pass">Password:</label>
        <input type="password" id="pass" required>
        <button type="submit">Connect</button>
    </form>
</body>
</html>

问题不是来自行动中的地址,该文件被很好地引用。

我知道我不应该使用GET来处理敏感数据,但是我使用了这种方法,因为它允许我轻松查看URL中的参数。

感谢您的帮助。

3 个答案:

答案 0 :(得分:2)

您需要使用name属性来传递这样的数据:

<form action="controller/connect_user.php" method="GET">
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>
    <label for="pass">Password:</label>
    <input type="password" id="pass" name="password" required>
    <button type="submit">Connect</button>

而不是:

<form action="controller/connect_user.php" method="GET">
    <label for="email">Email:</label>
    <input type="email" id="email" required>
    <label for="pass">Password:</label>
    <input type="password" id="pass" required>
    <button type="submit">Connect</button>
</form>

在你能得到这样的价值之后:

$email = $_GET['email'];
$password = $_GET['password'];

我建议您使用POST代替GET

答案 1 :(得分:2)

您需要为输入命名:

<form action="controller/connect_user.php" method="GET">
      <label for="email">Email:</label>
      <input type="email" id="email" name="email" required>
      <label for="pass">Password:</label>
      <input type="password" id="pass" name="password" required>
      <button type="submit">Connect</button>
</form>

然后,在您的PHP中,您可以访问它们,如:

echo $_POST['name'];

答案 2 :(得分:2)

输入需要名称属性,否则无法获得它(通过GET或POST)

<input type="password" id="pass" name="pass" required>