如果isset $ _POST [英] If isset $_POST

查看:64
本文介绍了如果isset $ _POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有一个表单提交到另一页面.在那里,它检查输入邮件是否已填充.如果是这样,则执行某些操作,如果未填满,请执行其他操作.我不明白为什么即使我发送一个空表格也总是说它已设置.什么遗漏或出了什么问题?

I have a form on one page that submits to another page. There, it checks if the input mail is filled. If so then do something and if it is not filled, do something else. I don't understand why it always says that it is set, even if I send an empty form. What is missing or wrong?

step2.php:

step2.php:

<form name="new user" method="post" action="step2_check.php"> 
    <input type="text" name="mail"/> <br />
    <input type="password" name="password"/><br />
    <input type="submit"  value="continue"/>
</form>

step2_check:

step2_check:

if (isset($_POST["mail"])) {
    echo "Yes, mail is set";    
} else {    
    echo "N0, mail is not set";
}

推荐答案

即使未填写,也始终设置大多数表单输入,因此您也必须检查是否为空.

Most form inputs are always set, even if not filled up, so you must check for the emptiness too.

由于!empty()已经同时检查了两者,因此您可以使用以下方法:

Since !empty() is already checks for both, you can use this:

if (!empty($_POST["mail"])) {
    echo "Yes, mail is set";    
} else {  
    echo "No, mail is not set";
}

这篇关于如果isset $ _POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆