Skip to content

Forms restrictions and anti spam measures

Michele Mizejewski edited this page Sep 13, 2021 · 19 revisions

Anti-spam measures for WPForms

All forms created with WPForms are protected.

  1. First, generate a reCAPTCHA key in Google. See plugin documentation for all details.
  2. Then go back to the WordPress dashboard > WPForms > Settings > reCAPTCHA and enter the key
  3. For each form, go to Settings > General and check Enable anti-spam honeypot and Enable Google Checkbox v@ reCAPTCHA

captcha settings

Forms restrict email domain

Problem

Need to limit submissions for DPH ILL requests to users with an email address @sfdph

Solution

WPForms provides options to limit or block email address form fields.

limit domain

Solution (older and no longer needed)

  1. Get a snippet from WPForms support and customize to include the desired domain and the specific form ID
/*
 * Whitelist email domains from your WPForms.
 *
 * @link https://wpforms.com/developers/how-to-restrict-email-domains/
 *
*/
function wpf_whitelist_domains( $field_id, $field_submit, $form_data ) {
    $domain          = substr( strrchr( $field_submit, "@" ), 1 );
    $whitelist       = array( 'sfdph.org' );
    if( ! in_array( $domain, $whitelist ) && $form_data[ 'id' ] == 15647 ) {
        wpforms()->process->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Email domain must be @sfdph.org', 'wpforms' );
        return;
    }
}
add_action('wpforms_process_validate_email', 'wpf_whitelist_domains', 10, 3 );
  1. Add the edited code via the plugin Code Snippets

snippets plugin

Clone this wiki locally