Filter Uncanny Redemption Codes

forminator_field_text_sanitize

Filters the sanitized value of a text field before it's saved, allowing for custom processing.

add_filter( 'forminator_field_text_sanitize', $callback, 10, 3 );

Description

Filters the sanitized data for Forminator text fields. Developers can use this hook to further process or modify the text input before it's saved or displayed. This filter is applied after the default sanitization process.


Usage

add_filter( 'forminator_field_text_sanitize', 'your_function_name', 10, 3 );

Parameters

$data (mixed)
The `$data` parameter contains the sanitized value of the text field.
$field (mixed)
This parameter contains the sanitized data that will be returned by the filter.
$original_data (mixed)
This parameter contains information about the specific field being processed.

Return Value

The filtered value.


Examples

/**
 * Example of using the forminator_field_text_sanitize filter to modify text field input.
 * This example will trim whitespace from the beginning and end of the text input
 * and convert it to lowercase.
 */
add_filter( 'forminator_field_text_sanitize', function( $data, $field, $original_data ) {

	// Ensure the data is a string before attempting to manipulate it.
	if ( is_string( $data ) ) {
		// Trim whitespace from the beginning and end of the string.
		$sanitized_data = trim( $data );

		// Convert the string to lowercase.
		$sanitized_data = strtolower( $sanitized_data );

		// You can also add more complex logic here, for example,
		// checking the field ID to apply sanitization only to specific fields.
		// if ( isset( $field['id'] ) && 'my-specific-field-id' === $field['id'] ) {
		//     // Apply more specific sanitization for this field.
		// }

		return $sanitized_data;
	}

	// If the data is not a string, return it as is.
	return $data;

}, 10, 3 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/integrations/forminator/class-create-codes-field.php:106

public function sanitize( $field, $data ) {
		$original_data = $data;
		// Sanitize.
		$data = forminator_sanitize_field( $data );

		return apply_filters( 'forminator_field_text_sanitize', $data, $field, $original_data );
	}

Scroll to Top