开发者

PHP: still work even if not isset

HTML new_password:

   <input name="new_password" type="password" maxlength="25" id="new_password" class="ModuleTextbox" onkeyup="var regex = new RegExp(/^.*(?=.{6,})(?=.*\d)(?=.*[aA-zZ@!¤&amp;/()_?,.-]).*$/m); if(regex.test(this.value)) { pwok.style.visibility = 'visible'; } else { pwok.style.visibility = 'hidden'; }" style="width:200px;" />&nbsp;<img id="pwok" src="ok.png"
                            alt="R" style="visibility: hidden;" />

php after submit form:

foreach开发者_Go百科($_POST as $key => $value) {
    $data[$key] = filter($value);
}
$pw_new = $data["new_password"];


   if(isset($pw_new)) {
echo "LOL";
}

even if i didnt write anything in the field, it echo's LOL, why's that?


Because the input is there, the form will still send it even if it's empty. So even if it's empty, it's still set, as in it still exists in $_POST, and so it'll still carry over to $data.

You should use !empty() (that means 'not empty') instead:

if(!empty($pw_new)) {
}


Even when you write nothing, you foreach will always set $data["new_password"], then it set $pw_new, you might want so check for values instead of isset

if ($pw_new != '') {
echo 'LOL';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜