Documentation

gwp_sanitize

The gwp_sanitize modifier is a merge tag modifier that allows to display sanitized values.

Usage

The modifier can be used within any Gravity Forms merge tag by appending it with specific attributes that define the sanitization behavior. The basic syntax is as follows:

{field:1:gwp_sanitize type="sanitize_text_field"}

Attributes

  • type – Specifies the sanitization method to be applied. Options include sanitize_text_field, sanitize_title_with_dashes, and trim.

Supported Sanitization Types

  • sanitize_text_field – Utilizes WordPress’s sanitize_text_field() function to strip all tags and encode special characters from the string.
  • sanitize_title_with_dashes – Employs sanitize_title_with_dashes() to sanitize a title or slug, replacing whitespace and a few other characters with dashes.
  • trim – Simply trims whitespace from the beginning and end of the string using PHP’s trim() function.
  • absint – Converts a value to non-negative integer.

Frequently Asked Questions

What does the gwp_sanitize merge tag do in Gravity Forms?

The :gwp_sanitize modifier lets you clean up a field’s value by removing tags, extra spaces, or unsafe characters before displaying it. It uses WordPress’s built-in sanitization functions like sanitize_text_field, trim, and others to make your output safer and more readable.

{Raw Input:1:gwp_sanitize}

How do I apply different sanitization types?

You can pass a type attribute inside the merge tag to choose how the text should be cleaned. Available options include sanitize_text_field (default), sanitize_title_with_dashes, trim, absint, and wp_strip_all_tags.

{Raw Input:1:gwp_sanitize type="sanitize_title_with_dashes"}

What’s the difference between sanitize_text_field and wp_strip_all_tags?

Both remove HTML, but in different ways. sanitize_text_field keeps text content and encodes special characters, while wp_strip_all_tags removes all HTML, XML, and PHP tags completely.

{Raw Input:1:gwp_sanitize type="wp_strip_all_tags"}

Can I sanitize numbers or slugs too?

Yes. Use absint to convert a value to a non-negative integer, and sanitize_title_with_dashes to turn a sentence into a URL-safe slug with dashes.

{Raw Input:1:gwp_sanitize type="absint"}

How do I test if gwp_sanitize works?

Use an HTML field or a confirmation message to show both the original and sanitized values. Try inputting tags or extra spaces, then compare the sanitized output to see the difference in real time.

<p>Original: {Raw Input:1}</p>
<p>Sanitized: {Raw Input:1:gwp_sanitize type="sanitize_title_with_dashes"}</p>

Last updated: 18-07-2025

Advanced Merge Tagsv1.9.3

To use the functionalities described in this documentation, you'll need to get the GravityWP - Advanced Merge Tags add-on.

Read more