PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Conditional fields for registered user

  1. I think I remember reading a similar question a while back but couldn't find it right now. I'm wondering if it's possible to have a form that had different fields based on if the user is logged in. For example I want to add a drop down that only the logged in user can see. The idea would be free and premium features.

    In my use case I want the logged in user to be able to select "e-mail, sms, or voice" where the logged out used doesn't get a choice it's just set to "e-mail"

    I'm pretty sure this currently can't be done but the work around would be to create two forms and then a custom template that uses the logged_in() function to see if they are logged in and if so shows one form if not shows the other. Before I went that route I just wanted to check here.

    Posted 13 years ago on Thursday April 7, 2011 | Permalink
  2. This is something we want to add. I'm not sure if we will add it to conditional logic, or it's own option. But it's definitely something that we plan on adding.

    Posted 13 years ago on Thursday April 7, 2011 | Permalink
  3. Okay, just wanted to make sure I wasn't missing anything :)

    Posted 13 years ago on Thursday April 7, 2011 | Permalink
  4. Thanks for asking this. I was wondering the same thing. The custom template option is a great workaround. Carl - I am loving this plugin and only wished I'd bought it long ago.

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  5. Jeff
    Member

    "Carl - I am loving this plugin and only wished I'd bought it long ago."

    Just thought I'd throw in my joy about this plugin also. Have had the dev license since many versions ago, and I can tell you its the single best thing I ever purchased to enhance Wordpress.

    There is no way I would want to face Wordpress without it.

    I also like the idea expressed above, one more reason Gravity rocks!

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  6. **Update:** Here is a more in-depth write up (with pictures!) of how this can be implemented.

    Here is an alternate concept for showing/hiding fields based on whether the user is logged in or not. We will use the the Gravity Forms' gform_field_value filter to dynamically populate a multiple choice field based on whether the user is logged in or not. We can then use Gravity Forms' conditional logic to show or hide fields based on our dynamically populated multiple choice field. Steps to recreate below:

    1. Create a multiple choice field with these settings:
      Standard Properties
      Advanced Properties
    2. Create a field that should only be visible to users who are logged in by setting the field's conditional logic to only show the field when our multiple choice field indicates that the user is logged in: Sample Logic.
    3. Now let's paste the code below into your theme's functions.php file: Magical Code.
      So what does this snippet do? Remember on step one when we created the multiple choice field and specified a dynamic population parameter titled "loggedin" under the Advanced properties tab? This snippet looks for any field with the "loggedin" population parameter and populates a value of 1 or 0 depending on whether the user is logged in.
    4. That should be it. If you access the form as a logged in user, your conditional field should show up. Now log out and access the form again. Your field should be hidden.
    Posted 13 years ago on Saturday April 9, 2011 | Permalink
  7. Thanks Dave. I'll give that a try soon and report back.

    Posted 13 years ago on Tuesday April 12, 2011 | Permalink
  8. Works great, the only problem is I'm able to override "gform_hidden" with a dom editor such as firebug. Not the biggest deal in my case but is there a way to fix this?

    Posted 13 years ago on Thursday April 14, 2011 | Permalink
  9. There is no way to fix this, dom editors are going to be able to override classes as well as Javascript if the user really knows what they are doing.

    Posted 13 years ago on Thursday April 14, 2011 | Permalink
  10. @Carl, Anyway to show/hide the "if logged in" field at the server (PHP) level?

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  11. No, there isn't currently a way to do this at the server level. It's a feature we would like to add, but it isn't something we have added yet. We just finished a huge development cycle for Gravity Forms v1.5 so our hands have been tied up with development related to that release. We'll start new feature development soon.

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  12. Thanks for the update. I just wanted to make it clear that I am always amazed at the great support and features you offer I just get curious and want to know if GF can do this or that. I'm not trying to belittle what it already does.

    Thanks for a great 1.5 release.

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  13. I completely understand, it's something we definitely plan on adding eventually. I definitely didn't take it as a belittling comment, we appreciate the feedback as it helps us shape future features to know what users want and deliver features that we know are in demand.

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  14. Hey, not sure if this is still an issue, but I've built this functionality out before. I built it on Gravity Forms 1.5.x, but it seems to work on 1.6.1 as well (haven't really tested it, though). If you want the code, you can find it here:

    https://gist.github.com/04943d6e99370542b38a

    That code would work fine as a mu-plugin, or, with some plugin headers added, as a regular plugin as well.

    Hope this helps!

    Posted 12 years ago on Tuesday November 8, 2011 | Permalink
  15. I would love to be able to get this to work as well.

    The only issue I am having with using the code provided by David Smith, is that I am trying to have this set on the post title.

    Reason being is that I want to have registered users the ability to submit a post, and it will be published automatically. But if you are not a registered member and you submit a post, it needs to be saved as a draft.

    In GF I cannot add more than one Title field in my form.

    Any workaround for this?

    Posted 12 years ago on Wednesday January 11, 2012 | Permalink