Is there a simpler function to something like this:
if (isset($_POST[\'Submit\'])) {
if ($_POST[\'login\'] == \"\" || $_POST[\'password\'] == \"\" || $_P
Personally I extract the POST array and then have if(!$login || !$password) then echo fill out the form :)
Something like this:
// Required field names
$required = array('login', 'password', 'confirm', 'name', 'phone', 'email');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
echo "All fields are required.";
} else {
echo "Proceed...";
}
Note : Just be careful if 0 is an acceptable value for a required field. As @Harold1983- mentioned, these are treated as empty in PHP. For these kind of things we should use isset instead of empty.
$requestArr = $_POST['data']// Requested data
$requiredFields = ['emailType', 'emailSubtype'];
$missigFields = $this->checkRequiredFields($requiredFields, $requestArr);
if ($missigFields) {
$errorMsg = 'Following parmeters are mandatory: ' . $missigFields;
return $errorMsg;
}
// Function to check whether the required params is exists in the array or not.
private function checkRequiredFields($requiredFields, $requestArr) {
$missigFields = [];
// Loop over the required fields and check whether the value is exist or not in the request params.
foreach ($requiredFields as $field) {`enter code here`
if (empty($requestArr[$field])) {
array_push($missigFields, $field);
}
}
$missigFields = implode(', ', $missigFields);
return $missigFields;
}