When a user submits a form its validated using if statements, like this
if (strlen($_POST['password']) < 5)
{
$data['errors'][] = 'Too short';
}
elseif ($_POST['password'] != $_POST['confirm_password'])
{
$data['errors'][] = 'doesnt match';
}
When validation is completed we check if there arent any errors
if (!$data['errors'])
And if it isnt we proceed and fill the data in to the database
However If there are errors, the USERS need to refill the whole form, I don’t want that, I need to render back some data if it’s legit
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$data['errors'][] = 'E-mail not valid';
}
Like here, if the password validation fails but the email validation is OK, I would want to give back the email already valued in the form. Would I need to put a else statement on every validation check like } else { $data[‘postback’][’email’]; } or could I do this on another easier way?
How can I do that?
The problem was solved with adding a else statement on the validation, if the validation was successfull I’d return the data to the rendering layout If something else on the validation failed.
Then I’d simply pass back the $data array, containing the post.email variable and outputting it on the screen.