Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

PHP can verify if a field is blank by using the empty() or isset() function.

The empty() function checks if a variable is empty or not, including if it is null, 0, "", false, or an empty array.

Example:

if (empty($_POST['field_name'])) {
  // Field is empty
} else {
  // Field is not empty
}

The isset() function checks if a variable is set and not NULL.

Example:

if (!isset($_POST['field_name']) || trim($_POST['field_name']) == '') {
  // Field is empty
} else {
  // Field is not empty
}

The above example also checks if the field is set and if it only contains white spaces.