How to make this email validation code for Bricks Form not reject an email address when it is correct?

I am facing an issue where, even if the email is correct, Bricks does not validate it.
On the contrary, it keeps displaying the following error message:
‘This email address is not in our system, sorry.’

You can check out the Bricks Form by clicking on the ‘Get Your Estimate’ button here: https://enviablescapes.com/

For the email validation I use the following code provided in Bricks Academy here: Form Element – Bricks Academy

HERE IS THE CODE:

add_filter( ‘bricks/form/validate’, function( $errors, $form ) {
$form_fields = $form->get_fields();

// Check if the form has a 'formId' field
if ( isset( $form_fields['formId'] ) ) {
    $form_id = $form_fields['formId'];
    
    // Skip validation if Form ID is not 'mpltpb'
    if ( $form_id !== 'mpltpb' ) {
        // Early return the $errors array if it's not the target form
        return $errors;
    }
} else {
    // Handle the case where 'formId' field is not present in the form
    // You may want to log or handle this differently based on your needs
    return $errors;
}

// Get submitted field value of form field ID '42ac96' (assuming it's an email field)
$email_address = $form->get_field_value( '42ac96' );

// Error: Email from unregistered user (show error message, and don't send email)
if ( ! email_exists( $email_address ) ) {
    // Add error message to the $errors array
    $errors[] = esc_html__( 'This email address is not in our system, sorry.', 'bricks' );
}

// Make sure to always return the $errors array
return $errors;

}, 10, 2 );

1 Like