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

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

    empty and isset should do it.

    if(!isset($_POST['submit'])) exit();
    
    $vars = array('login', 'password','confirm', 'name', 'email', 'phone');
    $verified = TRUE;
    foreach($vars as $v) {
       if(!isset($_POST[$v]) || empty($_POST[$v])) {
          $verified = FALSE;
       }
    }
    if(!$verified) {
      //error here...
      exit();
    }
    //process here...
    

提交回复
热议问题