首页 > 解决方案 > 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?

标签: phpdrop-down-menu

解决方案


我在 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;
}
?>

但是,这会在下拉列表底部留下一个空白选项字段,不知道为什么,此选项链接到产品。如果你返回页面,它需要你重新发送表单信息,这有点烦人。关于如何摆脱这些的任何提示?


推荐阅读