Hidden fields containing line breaks display visible <br /> tags in notifications and admin screens

I’ve got a form with a hidden field that is getting a value passed in via shortcode. The value contains line breaks. I’ve confirmed that in the raw HTML (via View Source) these are just invisible line break characters, not HTML <br /> tags.

I’ve also confirmed in the wp_gf_entry_meta table that they are just stored as invisible line break characters, not <br /> tags.

However, in both the notification emails and on the admin entry detail screen, these render as a visible <br /> on-screen (without a line break).

My guess is that somewhere along the way, both nl2br() and htmlentities() (or WP/GF functions that do similar things) are being applied to the text string.

Has anyone else run into this issue or know of a solution? Thanks!

I ran into the same issue when populating hidden fields with Javascript. You were on the right track–the value is indeed being run through nl2br().

I dug into the code that outputs fields and found that you need to use the gform_allowable_tags filter to allow HTML tags when outputting the affected fields in HTML format (on the admin entry detail screen and in notification emails).

Here is my code for your reference. It allows HTML tags for any hidden field in any form:

function gform_allow_hidden_field_html_tags($allow_html, $this, $form_id) {
    if ($this['type'] == 'hidden') {
        return true;
    return $allow_html;
add_filter('gform_allowable_tags', 'gform_allow_hidden_field_html_tags', 10, 3);
1 Like