Gravity Forms hook to ban a specific email address

On more than a few projects, I have ended up using Gravity Forms either because it was previously installed or was the need of the hour based on the requirements.

Recently, I was asked to ban a certain email address due to frequent spamming by the email address in concern. I am aware of the fact that the spammer can change email address and continue spamming. My task was simple, just ban the email address.

Here is how I chose to complete the task

Gravity forms plugin is highly customizable and makes its plethora of hooks available to help developers achieve the desired tasks. I used the validation gravity forms validation filter to filter the entered email address on submit.

I used the code below, to validate the entered email address and then check if the email address entered matched the address that needed to be banned. If the entered email address matches the emails specified, then a bool false status is set for the is_valid key in the result array and hence showing an validation error on submit.


function validate_email_ban( $result, $value, $form, $field ) {
// Check if the entered code is valid.
if ( $value == '' || $value == '' ) {
$result['is_valid'] = false;
$result['message'] = 'Email address is invalid.';
return $result;
add_filter( 'gform_field_validation_1_2', 'validate_email_ban', 10, 4 );




Read mode about the above field validation here

Gravity Forms is copyright of RocketGenius and you can use the plugin by downloading from their site or from the wordpress plugins directory.

, ,