How to Block Form Submissions by Keyword

WS Form gives you multiple ways to block keywords from being submitted through a form. This can be useful for preventing spam, enforcing content standards, or restricting specific terms.

WS Form - Limit by Keyword Blocklist - Invalid Feedback Example

The keyword matching is case-insensitive, meaning it doesn’t matter whether the word is in uppercase or lowercase.

To avoid false positives, WS Form performs whole word matching only. For example, if “art” is a blocked keyword, it will not trigger on safe words like “partial” or “startled.” This helps ensure that valid submissions aren’t mistakenly flagged.

Methods

There are two methods of blocking keywords:

Keyword Blocklist Setting

Each form can have an independent keyword blocklist. If a keyword is found when the form is submitted, WS Form will invalidate the field containing the keyword and show an invalid feedback message. You can either use the default invalid feedback message on the field or specify a custom message.

Enable Keyword Blocklist

To enable the keyword 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 Keyword Blocklist.

WS Form - Keyword Blocklist - Enable

Add Keywords

  1. Click the Add  icon under the Keywords setting.
  2. Enter a keyword. Keywords can also contain phrases.
  3. Repeat this for each keyword you want to add.

WS Form - Keyword Blocklist - Add Keyword

Optional – Set Invalid Feedback Message

If a blocked keyword is found in a submitted field, WS Form will display an error message next to that field. By default, it shows the field’s standard invalid feedback message.

To customize this message, simply enter your own text in the Invalid Feedback Message setting.

wsf_submit_block_keywords Filter Hook

The wsf_submit_block_keywords WordPress filter hook enables you to specify an array of blocked keywords that are checked when a form is submitted. WS Form will check all string based input again the blocked keyword array. If a blocked keyword is found, invalid feedback will be shown on the field.

By default this filter hook applies to all forms.

An example of using hook as as follows:

// Callback function for the wsf_submit_block_keywords filter hook
function my_hook_function( $keywords, $form, $submit ) {
    
    // Keywords to block
    $keywords[] = 'ranking';
    $keywords[] = 'seo';

    // Return value
    return $keywords;
}

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

If you need more control with keyword matching, consider using the wsf_submit_field_validate filter hook.

Related Hooks

Keyword Blocklist Add-On

The Keyword Blocklist add-on for WS Form makes it effortless to block unwanted spam by scanning form submissions for over 1,300 high-signal keywords across categories like Adult, Finance, SEO, and more. It’s incredibly easy to use. Simply toggle the categories you want to enable, and WS Form takes care of the rest. With built-in defaults for the most common spam types and full control over which categories are active, you can fine-tune protection without writing a single line of code.

The Keyword Blocklist add-on is available FREE for WS Form PRO users.