php - 表单 POST 提交未按预期生成 $_POST 键值
问题描述
大家好,提前感谢您的帮助,
我很难理解为什么我拥有的 PHP 代码没有遍历每个输入字段并发布/获取输出。
<html>
<body>
<!-- This PHP code will loop through all of the input fields and output the IDs and names. Both options of the get and post methods are checked. -->
<?php
foreach ($_POST as $key => $value) {
echo $key . ": " . $value . "<br/>";
}
foreach ($_GET as $key => $value) {
echo $key . ": " . $value . "<br/>";
}
?>
</body>
</html>
这是我想要开始工作的表格
<form class="form" action="response_page.php" method="post">
<div class="form__group">
<input type="text" placeholder="Username" class="form__input" required>
</div>
<div class="form__group">
<input type="email" placeholder="Email" class="form__input" required>
</div>
<div class="form__group">
<input type="password" placeholder="Password" class="form__input" required>
</div>
<input type="submit" name="submit" value="Submit" class="btn">
</form>
解决方案
表单中 html 输入元素的名称在表单提交时用作 http get/post 数组中的“键”。
您的输入元素没有任何名称属性。所以他们没有正确提交。为输入添加名称。例如
<input type="password" name=“password” placeholder="Password" class="form__input" required>
推荐阅读
- node.js - Fulfillment 中的 DialogFlow - 未定义 DeepLink
- c++ - 在 OpenGL 中使用透视 VS 正交投影时的光线投射(鼠标选择)
- jql - 显示有新评论的任务的 JQL 查询
- python-3.x - Python - 如何将字符串添加到列表项并返回修改后的列表项
- cuda - 如何解释 ptx 函数名
- time-complexity - 如何正式计算朴素多项式评估在某一点的运行时间
- git - git revert 未触发 Commit-msg 钩子
- c - 数组初始化中数组元素的赋值
- java - 如何单独格式化双值逗号
- javascript - 未捕获的引用错误:未定义 Excel