### [How to Block Form Submissions Containing Profanity](https://wpforms.com/developers/how-to-block-form-submissions-containing-profanity/)

**Published:** October 13, 2020
**Author:** Editorial Team

**Excerpt:** This tutorial will show. you how to use PHP to set up a profanity filter for your Single Line Text and Paragraph Text form fields. 

**Content:**

Would you like to block your form submissions containing profanity? You can easily create a list of expletive words that would stop any form submission if they are found inside your **Paragraph Text** or in a **Single Line Text** field using a small code snippet. In this tutorial, we’ll walk you through the steps on how to achieve this with PHP.

## Creating your form

First, you’ll need to create a new form and add either a **Paragraph Text** or a **Single Line Text**.

If you need any help in creating a form, [please see this documentation](https://wpforms.com/docs/creating-first-form/ "How to Create Your First Form").

![add a single or paragraph text form field to your new form](https://wpforms.com/wp-content/uploads/2020/10/wpforms-create-new-form.jpg)

## Blocking submissions containing profanity

Next, come up with a list of words you want to add to your profanity filter. Once you’ve identified the words you want to block you’ll need to add one of these snippets to your site. If you need any help in adding snippets to your site, [please see this documentation](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

You’ll just add each word to your **$blocked\_words** separated by a comma.

#### Paragraph Text Form Field

```

/**
 * Prevent profanity words from Paragraph Text form fields.
 *
 * @link https://wpforms.com/developers/how-to-block-form-submissions-containing-profanity/
 */

function wpf_dev_profanity_filter_paragraph( $field_id, $field_submit, $form_data ) {

        // Create your list of profanity words separated by commas
	$blocked_words = array( 
		'badword1', 
		'badword2'
	);

    foreach( $blocked_words as $word ) {
        if(strpos($field_submit, $word) !== FALSE ) {
            wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'No profanity allowed.', 'plugin-domain' );
            return;
        }
    }

}

add_action( 'wpforms_process_validate_textarea', 'wpf_dev_profanity_filter_paragraph', 10, 3 );

```

![Using this snippet will block submissions containing profanity inside the paragraph text form field](https://wpforms.com/wp-content/uploads/2020/10/wpforms-prevent-profanity-paragraph-text.jpg)

#### Single Line Text Form Field

```

/**
 * Prevent profanity words from Single Line Text form fields.
 *
 * @link https://wpforms.com/developers/how-to-block-form-submissions-containing-profanity/
 */

function wpf_dev_profanity_filter_single_text( $field_id, $field_submit, $form_data ) {

        // Create your list of profanity words separated by commas
	$blocked_words = array( 
		'badword1', 
		'badword2'
	);

    foreach( $blocked_words as $word ) {
        if(strpos($field_submit, $word) !== FALSE ) {
            wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'No profanity allowed.', 'plugin-domain' );
            return;
        }
    }

}

add_action( 'wpforms_process_validate_text', 'wpf_dev_profanity_filter_single_text', 10, 3 );

```

#### Rich Text Form Field

```

/**
 * Prevent profanity words from Rich Text form fields.
 *
 * @link https://wpforms.com/developers/how-to-block-form-submissions-containing-profanity/
 */

function wpf_dev_profanity_filter_rich_text( $field_id, $field_submit, $form_data ) {

        // Create your list of profanity words separated by commas
	$blocked_words = array( 
		'badword1', 
		'badword2'
	);

    foreach( $blocked_words as $word ) {
        if(strpos($field_submit, $word) !== FALSE ) {
            wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'No profanity allowed.', 'plugin-domain' );
            return;
        }
    }

}

add_action( 'wpforms_process_validate_richtext', 'wpf_dev_profanity_filter_rich_text', 10, 3 );

```

And that’s it! You’ve now created and implemented a profanity filter for your **Single Line** and **Paragraph Text** form fields. Would you like to block URLs from being entered into your form? Check out our tutorial on [How to Block URLs Inside the Form Fields. ](https://wpforms.com/developers/how-to-block-urls-inside-the-form-fields/ "How to Block URLs Inside the Form Fields")

## Reference Actions

- [wpforms\_process\_validate\_textarea](https://wpforms.com/developers/wpforms_process_validate_textarea/ "Using the wpforms_process_validate_textarea filter")
- [wpforms\_process\_validate\_text](https://wpforms.com/developers/wpforms_process_validate_text/ "Using the wpforms_process_validate_text filter")
- [wpforms\_process\_validate\_richtext](https://wpforms.com/developers/wpforms_process_validate_richtext/ "Using the wpforms_process_validate_richtext filter")

**Categories:** Fields

**Tags:** PHP

---

