html - 表单方法=发布和操作=index.php?page=somepage
问题描述
我正在编写一个在家庭服务器上运行的小脚本,它将通过 post 处理表单数据,但应该提交到带有获取值的页面。即 index.php 文件接收一个 $_GET ,它设置加载哪个页面。
如果页面 index.php?page=form 被加载,那么应该会出现一个表单,这很好,但表单处理在同一页面上。
有这样的表格:
<form action="index.php?page=form" method="post">
<input type="text" name="email">
Other form fields here
</form>
将数据发布到 index.php?而不是 index.php?page=form。
这可以做到吗?
解决方案
上面的代码对我有用。如果我按下回车键,我会进入站点 index.php?page=form。也许您的问题在其他任何地方。这里有两个选项,也许其中一个对您有用...
这对你来说可能吗?
如果没有设置$_POST,就会显示表单,如果提交表单,就可以处理数据。所以你不再需要 get 变量了。
<?php if (isset($_POST['email'])): ?>
<!-- process the inputs -->
<?php else: ?>
<form action="index.php" method="post">
<input type="text" name="email">
<!-- Other form fields here -->
<button type="submit">Submit</button>
</form>
<?php endif; ?>
如果您需要 $_GET 变量,请尝试
<?php
if ($_GET['page'] == 'form'):
//process the inputs
else: ?>
<form action="index.php" method="GET">
<input type="hidden" name="page" value="form">
<input type="text" name="email">
<!-- Other form fields here -->
<button type="submit">Submit</button>
</form>
<?php endif; ?>
推荐阅读
- java - 如何将带有页码的目录添加到 RTF
- java - 当我调用spring data JPA分页查询时,抛出'PageImpl:找不到合适的构造函数,无法反序列化'
- java - JAVA CardView 在 SDK 版本 28 中消失
- php - 尝试按日期对一系列 WordPress 帖子进行排序,最后使用空值
- java - 与 jdbc 相比,Hibernate(PostgreSQL)外键上的慢速选择查询 WHERE 子句
- javascript - 力有向图的链接端点总是粘在矩形节点的左角
- c++ - 为什么 range-v3 库中缺少 interleave_view?
- javascript - 如何在javascript函数中执行python代码(.py文件)?
- azure-active-directory - O365 - 无法在 SPPagecontextinfo 中获取访客用户电子邮件
- html - 在 CSS 中移动图像