PHP: check if any posted vars are empty - form: all fields required

后端 未结 9 1642
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 15:16

Is there a simpler function to something like this:

if (isset($_POST[\'Submit\'])) {
    if ($_POST[\'login\'] == \"\" || $_POST[\'password\'] == \"\" || $_P         


        
9条回答
  •  天涯浪人
    2020-11-27 15:48

    I use my own custom function...

    public function areNull() {
        if (func_num_args() == 0) return false;
        $arguments = func_get_args();
        foreach ($arguments as $argument):
            if (is_null($argument)) return true;
        endforeach;
        return false;
    }
    $var = areNull("username", "password", "etc");
    

    I'm sure it can easily be changed for you scenario. Basically it returns true if any of the values are NULL, so you could change it to empty or whatever.

提交回复
热议问题