【发布时间】:2009-07-10 20:36:02
【问题描述】:
我遇到了问题。我正在使用 Wordpress,但这不是 Wordpress 问题。
我正在使用两种表单,在一个表单上我有所有输入字段和一个隐藏输入字段,用于检查用户提交的表单。我已将其值保存为“保存”。还有另一种形式,仅用于重置所有选项,其值为“重置”。在 PHP 中,我检查隐藏字段的值并采取相应的措施。但问题是重置的东西不起作用。
这是我的表单 HTML:
<fieldset>
<form method="post">
<!-- Some input fields here-->
<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
</fieldset>
<fieldset>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</fieldset>
在 PHP 中,我这样验证它们:
// if I change the 'save' literal to something else like 'savea', $_POST variable will not be empty
// but if I dont, then $_POST variable is NULL
if ('save' == $_POST['action']) {
foreach ($this->cp_options as $option) {
if (isset($_POST[$option['id']])) {
update_option($option['id'], $_POST[$option['id']]);
}
else {
delete_option($option['id']);
}
}
header("Location: themes.php?page=functions.php&saved=true");
die;
}
// if I change the 'reset' literal to something else like 'reseta', $_POST variable will not be empty
// but if I dont, then $_POST variable is NULL
elseif ('reset' == $_POST['action']) {
foreach($this->cp_options as $option) {
delete_option($option);
}
header("Location: themes.php?page=functions.php&reset=true");
die;
}
问题是如果我将'reset' 或'save' 文字更改为'reseta' 或'saveasdfasd' 之类的任何其他内容,$_POST 变量不会为空,但如果我不这样做,那么$_POST 变量是NULL。
关于为什么会发生这种情况的任何想法?
【问题讨论】:
-
你能在 Wordpress 之外重新创建吗?
-
我不知道,但是 WordPress 是否有可能对 $_POST 和 $_GET 的内容做一些事情,可能是在它处理可能被破坏的(想想 magic_quotes)输入时? WordPress 是否有自己的机制来检索您可以尝试的表单值?
-
您的页面是否出现异常?如果是这样,您可以将其添加到您的问题中吗?我看不到 $_POST 变量会因为您更改代码中的字符串文字而突然变为空值,所以我想知道您的问题是否实际上不是您的诊断。或者也许你的措辞令人困惑。