How to Block Form Submissions by IP

WS Form gives you multiple ways to block form submissions by IP address. This can be useful for preventing spam.

IP address blocking occurs when the form is rendered. If a blocked IP is detected, WS Form will not render the form and will optionally show a message.

Note that IP address blocking is not processed when previewing a form.

Methods

There are two methods of blocking IP addresses:

IP Blocklist Setting

Each form can have its own IP blocklist. If a blocked IP address is detected when the form is loaded, WS Form will prevent the form from rendering. Optionally, you can display a custom message instead.

Enable IP Blocklist

To enable the IP blocklist feature:

  1. Click the Form Settings  icon at the top of the layout editor.
  2. Click the Spam tab.
  3. Check the Enable setting under IP Blocklist.

WS Form - IP Blocklist - Enable

Add IP Addresses

  1. Click the Add  icon under the IP Addresses setting.
  2. Enter an IPv4 or IPv6 IP address.
  3. Repeat this for each IP address you want to add.

WS Form - IP Blocklist - Add IP Address

Optional – Blocked Message

If a blocked IP address is detected, can also show a message to the end user. Simply enter your own text in the Blocked Message setting. If you leave this setting blank WS Form will not render the form and not show a message.

wsf_submit_block_ips Filter Hook

The wsf_submit_block_ips filter hook enables you to specify an array of blocked IP addresses that are checked when a form is submitted. WS Form will check the users IP address when the form is rendered. If a blocked IP address is found the form won’t be rendered and an optional message will be shown.

By default this filter hook applies to all forms.

An example of using hook as as follows:

// Callback function for the wsf_submit_block_ips filter hook
function my_hook_function( $ips, $form, $submit ) {
    
    // IPs to block
    $ips[] = '192.0.2.0';
    $ips[] = '2001:db8::';

    // Return value
    return $ips;
}

// Add a callback function for the wsf_submit_block_ips filter hook
add_filter( 'wsf_submit_block_ips', 'my_hook_function', 10, 3 );

Related Hooks