Gravity Forms: Hide field from logged in user

The conditional logic of Gravity Forms doesn’t really have a build-in option to hide a field from a logged in user, but you can accomplish this with some code.

Why would you want to hide a field from a logged in user? Take a contact form for example, if the visitor is not logged in you want to display the Gravity Forms Picatcha add-on, but you don’t want this for people who are logged in and have a certain capability set, like a trusted contributor. The Gravity Forms Picatcha add-on is available when you buy the Gravity Forms developers edition.

Here’s my solution, which is different from what I read in other articles I found on the Internet. I believe my solution is a bit more hack proof.

I’m using Gravity Forms v1.7.2 and Gravity Forms Picatcha Add-On 1.2 but I believe you can use this implementation starting with Gravity Forms v1.6.4.

Create the Gravity Forms form

We will create a standard contact form, just default values. We’ll called to form Contact Us.

We create several fields on the form:

  • Contact
  • Name
  • Email
  • Message
  • Hidden
  • Picatcha

I’m not explaining the first 4 fields, they are pretty standard and you can set them up the way you want to.

This field will be used for the conditional logic Gravity Forms offers. We’ll use this field in the Picatcha field.
We give the field the name “Token”.

Edit Form - Field Hidden

We also need to fill out the advanced options.
We set the default value to “no” , we allow this field to be populated dynamically and the parameter name will be hidden_token.
Edit Form - Field Hidden Advanced

I won’t go through the details of setting up Picatcha, but we need to setup the conditional logic, so this field won’t appear when a user is logged in and has a certain capability.
When the token has a certain value will we hide this field. The value is something we need later on when we do a bit of coding, I suggest you make it something random.
Edit Form - Field Picatcha Advanced

You might wonder why we want to hide when the field has a certain value. With the bit of code we will write, we’ll give the Token field this value when the conditions are met. This means that this “secret” token is only seen by people who are logged in and visitors of the page will have to guess how to bypass the Picatcha field.

Write the needed code

All the code can be added to your theme’s functions.php

Set up filter


 * All actions and filters for Gravity Forms
function GF_setup_actions_filters() {
	add_filter('gform_field_value_hidden_token', 'filter_GF_populate_hidden_token');

Explanation of the above code.

  • Line 7: This filter will run for the field token. If you named your parameter differently than ‘hidden_token’, substitute it here as well.

Populate function

 * Populate the field token.
 * This field exists in the contact form and is used as a conditional field for the picatcha field.
 * If that field has the value as given in this function, the picatcha field is not used.
 * We don't show the picatcha field for current members,
 * @uses $user_ID
 * @param string $value
 * @return string
function GF_populate_hidden_token ($value)
	global $user_ID;

	if ( is_user_logged_in() && user_can($user_ID, 'paidmember' ) {
		// The value must correspond with the value in the form itself.
		$value = "{secret_token}";
	return $value;

Explanation of the above code.

  • Line 17: Check if the user is logged in and has the given capability. You don’t have to check for a capability of course, my project just needed this as well.
  • line 19: This value should be the same as the value we set up in the form at the conditional logic

Final Thoughts
And that’s it. Now when a user is logged and, in my case has the capability of a paid member, we won’t show the Picatcha field.
If you find yourself thinking you want this on your site and you need Gravity Forms, please follow my link to buy Gravity Forms.
If you aren’t a programmer and you want this implemented on your site you can contact me and we can see if we can work something out.

This article is filed under the categories Development » WordPress » Code Snippet and has the following tag associated with it: .
  • I think there is typo in the last code snippet at line no. 17.

    Here you missed one parenthesis of if condition to be closed.

    if ( is_user_logged_in() && user_can($user_ID, ‘paidmember’ ) {


    though your article is very nice and very comprehensible and helped me a lot to dynamically condition the fields in a form.

    thanks a lot.

  • Another typo, I faced is in, first code snippet at line no. 7,

    add_filter(‘gform_field_value_hidden_token’, ‘filter_GF_populate_hidden_token’);

    The 2nd parameter ‘filter_GF_populate_hidden_token’ should not have the ‘filter_’ prefix. It’s working fine when we have the function name correctly as ‘GF_populate_hidden_token’


  • miss win

    hi all of you
    please how can i add a filter to submit a form