【发布时间】:2012-03-02 10:41:23
【问题描述】:
我在表达式引擎 (1.6.8) 模板中发布了一个表单。我正在使用 jquery 进行此操作,但也尝试了 HTML 表单 - 结果相同。 PHP 超全局 $_POST 在发布表单后为空,即使我在模板上启用了 PHP(在包含表单的模板的输入和处理模板上的输出)并且可以在 firebug 中看到 POST 变量。
任何人都可以提出可能导致这种情况的原因吗?
<html>
<head>
<script type="text/javascript" src="/_scripts/jquery-1.6.1.min.js"></script>
</head>
<body>
<form action="/select-locale/processing" method="POST">
<input type="text" name="test"/>
<input type="submit" name="submit" value="submit">
</form>
<a id="test" href="">link</a>
<script type="text/javascript">
$(function(){
$('#test').bind('click', function(e){
e.preventDefault();
var path = "/select-locale/processing"
var form = $('<form/>');
form.attr("method", "post");
form.attr("action", path);
var field = $('<input></input>');
field.attr("type", "hidden");
field.attr("name", 'locale');
field.attr("value", 'NZ');
form.append(field);
$('body').append(form);
form.submit();
});
});
</script>
</body>
</html>
服务器端代码(继承,不是我自己的):
<?php
var_dump($_POST);
var_dump($_GET);exit;
if ( ! isset($_POST['locale']))
{
$locale = FALSE;
$returnPage = "/";
}
else
{
$locale = $_POST['locale'];
$returnPage = $_POST['returnPage'];
}
if (isset($_GET['locale'])) {
$locale = $_GET['locale'];
$returnPage = "/";
?>
{exp:cookie_plus:set name="cklocale" value="<?php echo $locale;?>" seconds="2678400"}
{exp:session_variables:set name="userLocale" value="<?php echo $locale;?>"} <?php
}
?>
{exp:cookie_plus:set name="cklocale" value="<?php echo $locale;?>" seconds="2678400"}
{exp:session_variables:set name="userLocale" value="<?php echo $locale;?>"}
{exp:session_variables:get name="testSession"}
{if '{exp:session_variables:get name="testSession"}'=='yes' }
{redirect="<?php echo $returnPage;?>"}
{if:else}
{redirect="/nocookies/"}
{/if}
【问题讨论】:
-
不确定表单是否因为表单标签的操作属性或 jquery 函数中的 oath 值而被提交了两次
-
它是一个要求识别的授权密钥,通常附加在url中
-
为了调试,还要检查 $_REQUEST 数组。
标签: php forms expressionengine