Hide Administrative / Hidden visibility in DevTools

G’day,

Is there a way to hide a form field completely from the public / DevTools?

Marking the visibility of a field as “Hidden” or as “Administrative” is still visible in DevTools.

When I open the form in a private browser (ie not logged in) it shows the below (eg. when set to administrative)

<div id="field_89_67" class="gfield gfield--type-text gfield--input-type-text field_sublabel_below gfield--no-description field_description_above field_validation_below gfield_visibility_hidden"><div class="admin-hidden-markup"><i class="gform-icon gform-icon--hidden" aria-hidden="true" title="This field is hidden when viewing the form"></i><span>This field is hidden when viewing the form</span></div><label class="gfield_label gform-field-label" for="input_89_67">Profile Email</label><div class="ginput_container ginput_container_text"><input name="input_67" id="input_289_67" type="text" value="email@email.com" class="medium" aria-invalid="false"></div></div>

I’m looking to dynamically populate this field with people’s email address, so for security it can’t be seen in DevTools.

Cheers.

Hi there,

If a value is sent to the browser, it can always be seen in DevTools. Hidden and Administrative only hide it from view, not from the page code.

If you need the email to be truly hidden, set it on the server when the form is submitted so it never appears in the HTML. Use this snippet, and set the field to Administrative with dynamic population turned off:

add_filter( 'gform_pre_validation_89', 'gf_set_email' );
add_filter( 'gform_pre_submission_filter_89', 'gf_set_email' );

function gf_set_email( $form ) {
	$user = wp_get_current_user();
	if ( $user && $user->ID ) {
		$_POST['input_67'] = $user->user_email;
	}
	return $form;
}

Replace 89 with your form ID and 67 with your field ID.

If users are not logged in, there is no secure way to prefill their email without exposing it in the browser.

Please use this code in your child theme’s functions.php file or in a Code Snippets plugin.

Screenshots:

Give it a try, and let me know how that goes! :grinning_face_with_smiling_eyes:

Fields with the visibility set to Administrative aren’t rendered in the DOM/Dev Tools**. If this isn’t the case on your website, it’s either a bug or a 3rd party conflict, and I’d recommend opening a support ticket with Gravity Forms to help you diagnose the issue.

** Unless the Dynamic Population feature is enabled on the Administrative field.

1 Like

Thanks Jake! I’m using Dynamic Population so I’m guessing that’s the reason.

Many thank for replying