if ( ! empty( $form[ 'email' ] ) ) {
$validator = v::email()->validate( $form[ 'email' ] );
if ( $validator === false ) {
$formErrorBag[ 'email' ] = "Please enter a valid email";
}
} else {
$formErrorBag[ 'email' ] = "This field is required";
}
Here is code that handles email validation. There are several of these to handle various fields (username, passwords....).
This code is working, but I find it verbose. Would there be a more concise way of achieving the same?