php - 使用 PHP 提交具有不同提交按钮和表单的页面
问题描述
我一个人无法解决这个问题。我有 .html 文件,在正文部分,我正在使用 switch 导入一些 .php 文件。我正在显示表格,并使用 POST 表单在其上导航。现在我想添加到我的导航栏搜索输入,它也将通过 POST 发送数据。它位于头部标签上,当我按下按钮时,什么都没有发生。
索引.php
<html>
<head>
<div class="leftNav">
<a class="buttonNav" href="index.php?subpage=table&data=session&page=0">Session</a>
<a class="buttonNav" href="index.php?subpage=table&data=all&page=0">All</a>
</div>
<div class="rightNav">
<?php include 'navbars.php' ?>
</div>
</head>
<body style="font-family:Verdana;">
<div class="content">
<?php
if(isset($_GET['subpage']))
{
switch($_GET['subpage'])
{
case 'table':
include 'datatable.php';
break;
default:
include 'home.php';
break;
}
}
else include 'home.php';
?>
</div>
</body>
</html>
数据表.php
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if($_POST['search'])
{
$filtr = $_POST['filtr'];
$data = $_GET['data'];
header("
Location: index.php?subpage=table&data=".$data."&page=0&search=".$filtr);
}
else{...}
}
//DISPLAYING TABLE//
echo("
</table>
<form class='nav' method='POST'>");
$disabled = '';
if($curr+1 == 1)
$disabled = "disabled='disabled'";
echo("<input type='submit' name='f' value='First page' ".$disabled.">
<input type='submit' name='p' value='Previous page' ".$disabled."> ");
$disabled = "";
if($curr == $max)
$disabled = "disabled='disabled'";
echo("<input type='submit' name='n' value='Next page' ".$disabled.">
<input type='submit' name='l' value='Last page' ".$disabled."></form>");
?>
导航栏.php
<?php
if(isset($_GET['subpage']) && $_GET['subpage'] == 'table')
{
echo("
<form method='POST'>
<input type='text' name='filtr'>
<input type='submit' name='search' value='Search'>
</form>
");
}
?>
解决方案
如另一个答案中所述,您将需要使用该action
属性,但您需要传递以下内容$_GET['subpage']
:
action="<?php if(!empty($_GET['subpage'])) echo '?subpage='.htmlspecialchars($_GET['subpage'], ENT_QUOTES) ?>"
注意:我没有看到您实际上在脚本中发送
$_GET['subpage']
or的任何$_GET['data']
地方,所以我不知道它是否被正确调用。
推荐阅读
- python - 使用 Django rest 框架从 2 个不同的表中过滤
- r - 为分组箱线图排序数据集
- cypress - 在特定区域移动鼠标几次
- python - 有没有办法确保 Sqlite3 不会将其他整数 0 和 1 提交到布尔列
- python - 寻找最长簇的算法。(理想情况下是 Python,可能是 Matlab)
- jitsi - Jitsi Meet - 您已断开连接
- reactjs - 在没有 setState 的情况下响应本机状态更改
- python - 无法在 jupyter 笔记本中加载 libcudnn.so.7 而我可以在命令行中运行时加载它
- python - 比较 2 个 csv 文件并更新列
- python - 集群资源不足,无法启动试用 - 只有 0 个 GPU