Real-Time Email Validation in WordPress Forms Using Reoon API and Fluent Forms

When collecting data through forms on your WordPress site, ensuring the accuracy of submitted information—especially email addresses—is essential. Invalid or incorrect emails can result in lost communication and potential business opportunities. One effective solution to mitigate this issue is integrating real-time email validation into your forms. In this article, we will explore how to use the Reoon Email Verifier API in combination with Fluent Forms to validate email addresses before they are submitted.

Why Validate Emails in Forms?

Collecting invalid or non-functional email addresses can lead to problems such as:

  • Bounce Rates: Sending emails to non-existent addresses results in higher bounce rates, affecting your email deliverability and reputation.
  • Missed Opportunities: If a user submits an incorrect email, you won’t be able to communicate with them, leading to missed business opportunities.
  • Data Integrity: Invalid emails corrupt your database, making it harder to manage your contacts effectively.

By implementing real-time email validation in your forms, you can ensure that only valid email addresses make it through the submission process. This not only improves communication but also boosts the overall efficiency of your contact management efforts.

How the Reoon Email Verifier API Works

The Reoon Email Verifier API is an external service designed to validate email addresses by checking their authenticity and deliverability. It offers two validation modes:

  • Power Mode: Provides a deep validation of the email, including syntax checks, domain existence, and mailbox validation.
  • Quick Mode: Focuses on fast validation, offering a lightweight check to verify basic details.

When integrated with your WordPress forms, the API performs real-time verification of the email entered by the user. If the email is valid, the form submission continues. If not, an error message is displayed, preventing the submission of an invalid address.

Integrating Reoon Email Verifier API with Fluent Forms

To validate email addresses in Fluent Forms using the Reoon Email Verifier API, you can use the following custom WordPress filter. Here’s a breakdown of how it works.

1. Form-Specific Validation

First, the script checks if the form being submitted matches one of the specified form IDs. You can include multiple form IDs if needed. This ensures that email validation is only applied to the relevant forms on your site.

$targetFormIds = [9, 140, 141];
if (!in_array($form->id, $targetFormIds)) {
return $default;
}

In this case, form IDs 9, 140, and 141 are targeted. If the form ID doesn’t match any of these, the validation is skipped.

2. Checking the Email Field

Next, the script checks whether the email field is empty. If it is, the script will not proceed with the validation process, and the default behavior continues.

3. Sending a Request to the Reoon API

If the form contains an email address, the script sends a request to the Reoon Email Verifier API. It includes the email address and your API key, which you need to provide. The API returns a response indicating whether the email is valid or not.

$request = wp_remote_get('https://emailverifier.reoon.com/api/verify?email='.urlencode($email).'&key='.urlencode($reoonApiKey).'&mode=power');
4. Handling the API Response

The API’s response contains a status indicating whether the email is valid. If the response is positive ("valid"), the form submission proceeds as normal. If the email is deemed invalid, the script returns a custom error message such as “Looks like the email is not correct.”

if (isset($response['status']) && $response['status'] === 'valid') {
return $default;
}

This ensures that only valid emails can be submitted, preventing bad data from entering your system.

5. Error Handling

If for some reason the API request fails (e.g., due to a network issue), the form will bypass the custom validation and continue with its default behavior. This prevents users from being blocked from submitting the form due to external service failures.

if (is_wp_error($request)) {
return $default; // Request failed, so we are skipping validation
}

Customizing the Script

You can easily customize the script to fit your specific needs:

  • Target Specific Forms: Update the form IDs in the $targetFormIds array to control which forms use this validation.
  • Custom Error Message: Change the $errorMessage variable to display a message that matches the tone and style of your site.

Final Thoughts

Integrating real-time email validation into your WordPress forms is a great way to ensure you’re collecting accurate and functional email addresses. By leveraging the Reoon Email Verifier API in conjunction with Fluent Forms, you can reduce bounce rates, maintain data integrity, and improve communication with your users. This simple yet powerful solution ensures that your forms perform better and your contact list remains clean and actionable.

Take the step to implement email validation today, and watch the quality of your submissions improve!

I use fluent snippet plugin for all my functions, js, and CSS:

Here is the code I used. Please sign up for a free account at Reoon and on lime 4 replace the api key with the one you generate.

add_filter('fluentform/validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {

    // Update with your specific form IDs
    $targetFormIds = [1,2,3,4,6]; // Add form IDs here
    $errorMessage = 'This email address is invalid or has been reported as spam before!'; // Custom error message
    $reoonApiKey = 'YOUR API KEY GOES HERE'; // Add your Reoon API key here
    
    // Check if the current form's ID matches one of the target form IDs
    if (!in_array($form->id, $targetFormIds)) {
        return $default;
    }

    $fieldName = 'email'; // Update this to match the name of the email field in your form
    
    // Check if the email field is empty
    if (empty($formData[$fieldName])) {
        return $default;
    }
    
    $email = $formData[$fieldName];

    // Send a request to the Reoon API to verify the email with the "mode=power" or "mode=quick" parameter
    $request = wp_remote_get('https://emailverifier.reoon.com/api/verify?email='.urlencode($email).'&key='.urlencode($reoonApiKey).'&mode=power');

    // Check if the request resulted in an error
    if (is_wp_error($request)) {
        return $default; // Request failed, so we are skipping validation
    }

    // Retrieve the response from the Reoon API and decode it as JSON
    $response = wp_remote_retrieve_body($request);
    $response = json_decode($response, true);

    // If the email is valid, return the default result
    if (isset($response['status']) && $response['status'] === 'valid') {
        return $default;
    }

    // If the email is not valid, return the custom error message
    return $errorMessage;

}, 10, 5);

Deep Dive Summary:

This text discusses using the Reoon Email Verifier API to validate email addresses within Fluent Forms on WordPress websites. It explains the benefits of real-time email validation, including reduced bounce rates, improved communication, and enhanced data integrity. The text then outlines how the Reoon API works, providing a detailed step-by-step guide to integrating the API into Fluent Forms, including code examples for customization. Ultimately, the author encourages readers to implement email validation to improve the quality of form submissions and enhance contact management.

Notes:

Wp Scriptly

This basic script, CSS style, and plugin are designed to function optimally assuming minimal interference from your theme or other plugins. If conflicts occur or further customization is needed, additional adjustments may be necessary. Please note that this script, CSS style, or plugin must be used AS IS.

Wp Scriptly

Newsletter Signup

WP Scriptly Newsletter

The WpScriptly Monthly newsletter offers top insights for WordPress pros: new scripts, plugins, resources, tips, tools, updates, and more every month.
*Wp Scriptly will not share or sell your name and email adress to anyone!

Comments: