【发布时间】:2014-10-27 08:58:42
【问题描述】:
我一直在尝试使用 foreach 替换 $_POST(s) 的每个 isset。
这是对每个 $_POST 使用 isset 的真实代码:
<form method='post'>
<input type='text' name='name'> <br>
<input type='text' name='address'> <br>
<input type='submit' name='send'>
</form>
<?php
if (isset($_POST['name']) && isset($_POST['address']) && isset($_POST['send']))
{
echo "All elements have been submitted";
}
else
{
echo "You forget some elements, try checking name or address";
}
?>
有没有一种方法可以将上面的 4 个 isset 替换为每个使用的单个 isset? 我做了这个,但它出错了。
<form method='post'>
<input type='text' name='nama'> <br>
<input type='text' name='alamat'> <br>
<input type='submit' name='kirim'>
</form>
<?php
foreach($_POST as $value)
{
if (isset($value))
{
echo "All elements have been submitted";
}
else
{
echo "You forget some elements, try checking name or address";
}
}
?>
需要帮助,如果我必须为通过 post/get 发送的每个元素一个一个地编写 isset,那只是在浪费时间。我以前在visual basic中看到过这样的东西,我的朋友做了一个foreach结构来验证表单中的所有文本框,所以他不再需要创建这样的东西了:
if textbox1.text="" && textbox.2.text="" and so on
【问题讨论】:
标签: php