I have a form to register users and I have a variable called $errors
where I concatenate all the errors that the form throws.
What I want to do is make a loop to go through and print on the screen in a list all the errors that the form throws.
if(empty($name)){
$errors = 'Debes colocar tu nombre';
}
if(empty($surname)){
$errors .= 'Debes colocar tu apellido';
}
if(empty($email)){
$errors .= 'La dirección de correo electrónico no puede estar vacio';
}
This is how I concatenate the errors into the variable by $errors
putting a dot before the equals sign "="
I hope you can excuse me because as far as I understand this is a forum to solve errors.
You can do it with array
Assuming that the values come in the super globlar
$_POST
(or$_GET
), depending on the form method, you could use ternary operators to evaluate the state of the variables and/or fill the array with errors.The reading of the array would be like this:
Example of output in case of error in everything:
PS: If you are not interested in differentiating the errors by key in the array, you can simply fill it like this:
and the reading would be done like this: