I am trying to create a form where if a user doesn't enter information into a specific input then on submission of the form, the user is alerted to fill in that input field only (e.g. "Please enter a username").
Currently I have a foreach loop that loops through each input field of the form and assigns a variable with the same name as the field (i.e. $name = $_POST['name']).
What would I implement in my code so I could check each individual input field is empty or not and tell the user this, but keep the code to a bare minimal?
foreach ($_POST as $key => $value) {
$$key = $_POST[$key]; //assigns variable to input.
}
if(!empty($$key)) {
//code if all fields are not empty
}
else {
echo "Please fill in all fields";
}