Description

The wpforms_process_validate_textarea action fires validation on the Paragraph Text form field when the form is submitted.

Parameters

$field_id
(int) Field ID.
$field_submit
(array) Original raw/unsanitized field value submitted for the field.
$form_data
(array) Processed form settings/data, prepared to be used later.

Source

wpforms/includes/fields/class-base.php

More Information

The wpforms_process_validate_textarea action is applied to an array for Paragraph Text form field. This function can be used for all form fields do_action( wpforms_process_validate_{$field_type}, $field_id, $field_submit, $form_data ).

For example, to use this for an Email field, you would use do_action( wpforms_process_validate_email, $field_id, $field_submit, $form_data ).

It’s important to note that field values are not sanitized until later on in the processing, at wpforms_process_format_{$field_type}.the

Examples

You can use this action to scan the Paragraph Text for a list of words that you’d like block the form from sending, such as profanity or you could use this action to look for certain words that would trigger another action like setting a value in a hidden field on your form that you can filter from entries.

This example, we’re going to search for any profanity in this field. If there is any profanity, the form will display an error and not send.

/*
 * Check the paragraph text field for profanity.
 *
 * @link https://wpforms.com/developers/wpforms_process_validate_textarea/
 *
 * @param int     $field_id        Field ID.
 * @param array   $field_submit    Unsanitized field value submitted for the field.
 * @param array   $form_data       Form data and settings.
*/

    // Optional, you can limit to specific forms. Below, we restrict output to
    // form ID #1423.
    if ( absint( $form_data[ 'id' ] ) !== 1423 ) {
        return;
    }

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.', 'wpforms' );
            return;
        }
    }
 
}
 
add_action( 'wpforms_process_validate_textarea', 'wpf_dev_profanity_filter_paragraph', 10, 3 );

Article References: