存在隐藏的输入类型时,不返回任何POST数据 [英] No POST data being returned when hidden input type is present
问题描述
我认为我的代码中有错误,或者我的PHP或Apache设置不正确.
I think that there is either an error in my code, or my PHP or Apache is set up incorrectly.
提交表单中包含隐藏字段的表单时,我的$ _POST数组中没有任何数据...
When I submit a form with a hidden field in it, I do not get any data in my $_POST array...
当我注释掉代码中的隐藏字段时,POST数据将正确返回...
When I comment out the hidden field in my code, the POST data is returned correctly...
HTML表单
<form action='/utils/login.php ' method='POST'>
<table>
<tr>
<td colspan='2'>
Login
</td>
</tr>
<tr>
<td>
Username
</td>
<td>
<input type='text' name='userid' value='' size='12' />
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type='password' name='password' size='12' />
</td>
</tr>
<tr>
<td>
<input type='hidden' name='formtype' value='login' />
</td>
</tr>
<tr>
<td>
<input type='submit' value='Submit' />
</td>
</tr>
</table></form>
这是在PHP中处理它的代码...
Here is the code that is processing it in PHP...
foreach ($_POST as $var => $value) {
echo "$var = $value<br>";
}
我在服务器上使用PHP 5和Apache 2.2.
I am using PHP 5 and Apache 2.2 on my server.
有什么想法吗?
编辑...
我将范围缩小到了这个...
I have narrowed it down to this...
$command = $_POST['formtype'];
当我从$ _POST删除@符号时,出现以下错误...
When I removed the @ sign from my $_POST, I am getting the following error...
注意:未定义的变量:第17行的C:\ webroot \ utils \ login.php中的表单类型
Notice: Undefined variable: formtype in C:\webroot\utils\login.php on line 17
如果我将该行注释掉,则POST数据将毫无问题地传递到程序中.
If I comment out that line, the POST data is passed into the program without a problem.
推荐答案
您是否尝试过将隐藏的输入从表中取出并放在开始表单标记之后?
Have you tried taking the hidden input out of the table and placing it right after the opening form tag?
您还可以使用:
var_dump($_POST);
...查看帖子变量.
...to view the post variables.
此外,如果正在动态创建任何输入或POST变量中可能缺少这些输入,则可以使用:
Also, if any inputs are being dynamically created or might be missing from the POST variables... you can use:
variable = 'default';
if(isset($_Post['variable'])) $variable = $_POST['variable'];
...动态设置可能存在或不存在的变量.
...to dynamically set variables that could be there or not.
这篇关于存在隐藏的输入类型时,不返回任何POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!