Using Gravity Forms ‘gform_allowable_tags’ PHP filter

The gform_allowable_tags filter allows you to enable HTML or specify accepted HTML tags in submitted entry data when using Gravity Forms.

Usage

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

Parameters

  • $allowable_tags (string | boolean): Default value is always false. See examples below for details.
  • $field (Field Object): The field currently being processed.
  • $form_id (integer): The ID of the current form.

More information

See Gravity Forms Docs: gform_allowable_tags

Examples

Allow basic HTML tags

add_filter('gform_allowable_tags_6', 'allow_basic_tags');

function allow_basic_tags($allowable_tags) {
    return '<p><a><strong><em>';
}

This code allows basic HTML tags like <p>, <a>, <strong>, and <em> for form ID 6.

Allow all WordPress permitted tags

add_filter('gform_allowable_tags_6', '__return_true');

This code allows all HTML tags that WordPress permits in post content for form ID 6.

Disable sanitization

add_filter('gform_allowable_tags_6', '__return_false');

This code disables sanitization for form ID 6, but the value may still be sanitized before it is displayed in the admin or when merge tags are processed.

Allow custom HTML tags for a specific field

add_filter('gform_allowable_tags', 'allow_custom_tags', 10, 3);

function allow_custom_tags($allowable_tags, $field, $form_id) {
    if ($form_id == 6 && $field->id == 2) {
        return '<div><span><ul><li>';
    }
    return $allowable_tags;
}

This code allows custom HTML tags like <div>, <span>, <ul>, and <li> for form ID 6 and field ID 2.

Limit allowable tags for a specific form and field

add_filter('gform_allowable_tags', 'limit_tags_for_field', 10, 3);

function limit_tags_for_field($allowable_tags, $field, $form_id) {
    if ($form_id == 7 && $field->id == 3) {
        return '<p><a>';
    }
    return $allowable_tags;
}

This code limits allowable HTML tags to <p> and <a> for form ID 7 and field ID 3.