php - PHP Dropdown 动态页面填充
问题描述
是否可以使用纯 PHPinclude_once 'template.php'"
从下拉菜单中进行选择?
在我的脑海里,它应该是这样的:
<?php
Connections to db
Include libs etc
Include header.php
?>
<Form to select which include template.php to display>
<?php
Include dynamictemplate.php <- from form dropdown on select.
Include footer
?>
还是我最好为此使用 AJAX 或 JS?
解决方案
我在 PHP 中找到了一种方法。
<form name="form1" method="POST" action="manage.php">
<select name="select" onChange="document.form1.submit()">
<option selected>Select a Table</option>
<option value="product">Product</option>
<option value="series">Series</option>
<option value="set">set<option>
</select>
</form>
<?php
if (isset($_POST['select']) && $_POST['select']) { } else { include
manage_product.php'; }
if (isset($_POST['select']) && $_POST['select'])
{
if ($_POST['select'] == 'product')
include 'manage_product.php';
if ($_POST['select'] == 'series')
include 'manage_series.php';
if ($_POST['select'] == 'set')
include 'manage_set.php';
} else {
return;
}
?>
但是,这会在下拉列表底部留下一个空白选项字段,不知道为什么,此选项链接到产品。如果你返回页面,它需要你重新发送表单信息,这有点烦人。关于如何摆脱这些的任何提示?
推荐阅读
- c# - UWP 键盘加速器 FN 问题
- python - 网络抓取 python/pandas 时忽略丢失的表:mlb 数据
- python-3.x - 如何使用 python selenium 从页面中递归地刮取表格
- linux-kernel - ACPI 定义块:系统总线的 _SB 和 _SB_ 之间的区别
- html - 转换 translateY 在 Safari 上不起作用
- c++ - 使用 cmake 静态链接到 Linux 中的 C++ AWS 开发工具包会因链接到共享对象文件而失败
- django - 在 Django 模型字段中存储层次结构/树?
- javascript - 如何在使用 JavaScript 或 jQuery 选择父选项时进行选择
- angular - Angular 6 - 使用范围外的函数和回调函数
- python - 对象没有属性 JSON