【发布时间】:2011-11-05 09:37:52
【问题描述】:
如果值字段 txtname 为空 echo It is ok 但它在我的代码中不起作用(如果字段为空并单击按钮,您会看到带有 print_r(...) 的输出),请参阅我的演示和我的代码。我该怎么办?
演示: http://codepad.viper-7.com/FNWcIs
<form method="post">
<input name="txtname[]">
<button>Click Me</button>
</form>
<?php
if ($_POST) {
$txtname = $_POST['txtname'];
if (!empty($txtname)) {
echo '<pre>';
print_r($txtname); // Output this is: Array ( [0] => )
} else {
echo 'it is ok';
}
}
?>
【问题讨论】:
-
试试
var_dump($_POST)你会得到什么? -
@ Truth - 见这里:codepad.viper-7.com/UXe1ZC 并点击按钮
Click Me