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

后端 未结 9 1554
伪装坚强ぢ
伪装坚强ぢ 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:44

    I did it like this:

    $missing = array();
     foreach ($_POST as $key => $value) { if ($value == "") { array_push($missing, $key);}}
     if (count($missing) > 0) {
      echo "Required fields found empty: ";
      foreach ($missing as $k => $v) { echo $v." ";}
      } else {
      unset($missing);
      // do your stuff here with the $_POST
      }
    

提交回复
热议问题