【发布时间】:2011-11-06 02:46:03
【问题描述】:
我正在尝试让 HTML/PHP 表单正确提交。一些细节:
基本网址 = http://localhost/directory
页面 = page/add
完整地址 = http://localhost/directory/page/add
使用htaccess重写url,所以http://localhost/directory/page/add其实就是http://localhost/directory/index.php?q=page/add
我的 HTML POST 操作是“页面/添加”,以便前端控制器知道要触发哪个函数来清理和提交数据(它充当“表单 ID”)。
页面在http://localhost/directory/page/add 处加载正常,但是当我单击提交按钮时,URL 被修改为页面/页面/添加。每次我按“提交”时,都会在网址中添加另一个“页面”。所以点击 5 次会得到“page/page/page/page/page/page/add”
我似乎无法找到为什么我会得到那个“额外的”“页面”。
实际的 PHP 错误(page/page/add 在 $routes 中不存在,因为它不是有效的路由):
注意:未定义的索引:第 92 行 C:\xampp\htdocs\script\includes\common.inc 中的页面/页面/添加
这是第 92 行的函数:
function route_path($path = NULL) {
$routes = get_routes(); //Returns array: approved "urls => function callbacks"
if($path === NULL) {
$path = get_path(); //Returns $_GET['q'] with trim and strip_tags
}
$function = $routes[$path]; <<<<<----This is LINE 92
if(isset($function)) {
$form_name = str_replace('/', '_', $path); // page/add = function page_add()
}
if(function_exists($function)) {
call_user_func($function, $form_name);
}
else {
//TODO: Redirect to Login screen.
}
}
基本的 HTML 是:
<form action="page/add" method="post" />
//Form elements
<input type="submit" value="Submit" />
</form>
感谢您的帮助。
更新:我所做的是将<base> 标记添加到我的HTML 模板中。这使我可以将操作保留为页面/添加(因为它也是我的简单路由器/调度程序中的路由)。
【问题讨论】:
-
表格的网址是什么?你知道
page/add是相对于当前的吗?如果您的表单的 URL 以/结尾或不以/结尾,这将有所不同。