Skip User Registration For Logged In Users

February 20, 2020: Fixed issues caused by failure to return $form object.

November 16th, 2015: Update to work with GFUR v3.0.beta1+. Props to GF team member Richard Vav.

If you’re using the Gravity Forms User Registration Add-on, this snippet will allow you to skip registration for users who are logged in when they submit the form.

This snippet was written to assist a fellow who had configured a form that allowed users to optionally register an account on the site. This much is handled out of the box by the GF User Registration Add-on.

The issue arose when users, who opted to create an account on their initial submission, neglected to click the checkbox which opted them out of creating an account on their subsequent submissions. This resulted in a validation error; the submitted email was already registered to a user on the site!

Of course it was! It is the very email the user previously created an account with. The solution? If the user is logged in skip the registration completely. Be sure to display a message somewhere on your form instructing users to login if they already have an account.

Comments

  1. Paul Young
    Paul Young March 27, 2024 at 7:56 am

    Hello, When using this with a nested form that has registration it will skip, can we assign this to only work with one form on the website?

    Reply
  2. Bart Schelstraete
    Bart Schelstraete May 8, 2021 at 9:37 pm

    I’m using a form with woocommerce & yith. If user is logged in, the form will get the name/address from the database. Using the User Registration Add-on, the name/address will be updated in the database in case the user modifies the name/address. (using the change option only in user registration add-one) That works fine. Now, the problem is that the same form is also used for non logged in users, where the user registration add-on should not be triggered of course. But even when I use the conditional access, where I configure “user must be logged in”, the user gets the message that he should be logged in for using this form. (this is definitely coming from the user registration addon), as it’s gone when disabling the add-on). Then I used this snippet over here, hoping that this would resolve the issue, but even when using this snipper I’m getting the message that the user should be logged in?

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff May 10, 2021 at 6:00 am

      Hi Bart,

      My guess is that, when a User Registration Update User Feed is set up on a form, the form will only be accessible to logged-in users. As far I am aware the same form cannot be used for new user registrations and user updates simultaneously. So if the Non logged in users will be creating new user accounts then you’ll have to create separate forms for these.

      Best,

  3. Amin Jabari
    Amin Jabari April 14, 2021 at 5:28 am

    Hi Is it possible to skip registration for ” registered username”?

    I have a form that triggers multiple sets of actions. (creating a user is one of these actions) Normally, when I use a username that has been used, the form shows an error that this username is registered. I want to deactivate registration when this situation occurs and submit the form anyway,

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff April 14, 2021 at 7:25 am

      Hi Amin,

      We have a snippet that skips registration if Email exists, you may want to check it out and give it a try.

      Best,

    1. stephane samandoulougou
      stephane samandoulougou March 30, 2020 at 3:02 pm

      Thank you for your answer. At the very beginning I copied the code into my funtions.php file but nothing happens in my site.

      I installed gravity forms, the gravity useregistration and paypal payment module. Should i installed gravitywiz?

    2. Ryan Donovan
      Ryan Donovan March 30, 2020 at 4:45 pm

      Hey Stephane, What version of User Registration are you using? Please note: This snippet has been updated to work with the very latest version of the Gravity Forms User Registration plugin (3.0.beta1+). If you’re not ready to upgrade or need to accomplish this functionality on an earlier version, use this snippet instead. You should be fine with your setup plus this snippet. If you’re a Gravity Perks customer, we’ll be happy to provide support via the support form.😁

  4. Fabienne Wintle
    Fabienne Wintle July 26, 2018 at 8:28 pm

    Hi, is there a way to actually display the form to non logged in users if user registration (update user) is turned on? I have a form that I would like both logged in and logged out users to use, and user registration is enabled with conditional logic to only apply to users that are logged in. However, even with this logic being applied the form does not display if users are logged out. Which doesn’t make sense.

    So I found your gist which does the opposite of what I need and was wondering if you had something to achieve my objective?

    Reply
    1. Ibraheem
      Ibraheem June 26, 2019 at 8:05 am

      Hi David, I’m having this issue also, so I’d be grateful if you have a solution. When selecting ‘Update User’ for the form action, the form then seems to be locked for users who are not logged in. The use case is for ensuring that logged in users don’t have to fill out information they’ve already entered in the past, but still allow guest users to submit as well (without creating a new user of course). Do you know of a solution to this?

  5. Jeffrey
    Jeffrey June 20, 2018 at 3:00 am

    I added the code to my functions.php , but now when I fill in my form the confirmation email from the form does not arrive to my email…

    Reply
    1. David Smith
      David Smith Staff June 20, 2018 at 7:54 am

      Hi Jeffrey, this doesn’t interact with the confirmation functionality so it is unlikely that this snippet is interfering with any core Gravity Forms functionality. If you’re a Gravity Perks customer, we’ll be happy to provide support via the support form.

  6. gform_is_delayed_pre_process_feed – Gravity Forms Documentation October 4, 2017 at 3:11 pm

    […] This example prevents the User Registration ‘create’ feed running if the user is logged in. Read the full tutorial for details and the second part of the code snippet. […]

    Reply
  7. Seb
    Seb June 25, 2017 at 7:55 am

    Is it possible to customize this code? I would like to do following:

    If Email Address exists skip registration and update data for non-logged-in-users

    Thx

    Reply
    1. Seb
      Seb June 25, 2017 at 8:56 am

      Hi David, thx.

      I`ve just tested it. But it only says if user is not logged in: Email alreads exists.

    2. Tim French
      Tim French August 14, 2017 at 8:58 am

      Hi David, just wondering if you where considering a version for create feeds?

      the problem is causing me a few headaches at the mo…..

      Tim

    3. David Smith
      David Smith Staff August 14, 2017 at 11:15 am

      Hi Tim, I don’t have any definite plans but if you’d like to commission the functionality, I’d be happy to discuss: david at graitywiz dot com

  8. Kev Xaveus
    Kev Xaveus April 22, 2017 at 9:08 am

    noob question: where does the snippet need to be pasted? Does it go in the theme’s functions.php or the WP-includes functions.php?

    Does it go at the top or end of the PHP file and does it go within the main <PHP? content or does it keep its own PHP bracket?

    Could you post a screenshot of it pasted as it should be please?

    Reply
    1. David Smith
      David Smith Staff July 14, 2016 at 7:51 pm

      Are you using the latest version of the snippet above? Is the user actually logged in?

    2. Marshall
      Marshall July 14, 2016 at 7:58 pm

      yes…the above code.

      yes…admin logged in..

      I wanted the field to show when user role is administrator.

      Can you give me example on how I can do this?

    3. David Smith
      David Smith Staff July 14, 2016 at 8:10 pm

      Hi Marshall, I just confirmed that this snippet is working for me. Based on your last comment, I think you might be wanting to hide a field based on the user role. You can do this by populating the user role into a field on the form and then basing the conditional logic on the value of that field. This will help:

      https://gravitywiz.com/dynamically-populating-user-role/

  9. Tuhin Bhuiyan
    Tuhin Bhuiyan June 10, 2016 at 12:54 pm

    Is this snippet still working?. for version RC1 beta3.

    For me, it is still showing the user field and asking for validation.

    Reply
    1. David Smith
      David Smith Staff June 30, 2016 at 10:03 am

      Hi Tuhin, yes, this is working on our end with the latest versions of Gravity Forms and GF User Registration.

  10. Russell Weller
    Russell Weller December 17, 2015 at 5:31 pm

    Hi. I am trying to modify your snippet to skip registering the user if a user already exists. Having some problems though. Wondered if you might be able to help …

    Here’s what I’ve got so far, but the registration goes through even though the value of Form ID 1, Field ID 11 matches an existing user, which then throws an error on the front-end since the username already exists.

    [code removed]

    Reply
    1. Russell Weller
      Russell Weller March 28, 2016 at 12:18 pm

      Hi David! The pastie code you posted was working great, but seems to have broken on updating to GF 1.9.17.5 and User Registration 3.2.1. Any ideas?

    2. Russell Weller
      Russell Weller March 28, 2016 at 12:38 pm

      I can get it to work if I remove the “username_exists( rgpost( ‘input_17’ ) ) &&” from line 18. The ID of the input field I am checking is definitely 17, so not sure. That removes all validation on forms that Create a User though, not just the ones that have duplicate usernames.

    3. David Smith
      David Smith Staff March 29, 2016 at 8:07 am

      Hey Russell, I took another look at the snippet and I can’t see any reason it shouldn’t work. You may need to hire a developer to assist with this one.

  11. Naser
    Naser October 7, 2015 at 6:01 pm

    Great Post!

    I have some other remaining problems with Gravity Form :

    1.) I would like to completely disappear User Registration form as an option to menu and the page for Login Users.

    2.) In an other form under Restrictions I have use “Require user to be logged in” but instead of “Require login message” I would like to make redirect user to login page.

    Do you have any idea, how to implement all the above?

    Thank You!

    Reply
    1. David Smith
      David Smith Staff October 8, 2015 at 5:23 pm

      1 – Install the Members plugin and modify the user role for your users so that they do not have the “gravityforms_user_registration” capability. This will prevent users from seeing the User Registration menu item.

      2 – I would bind a function to the gform_pre_enqueue_scripts action. It passes the $form object as the first parameter. If the $form[‘requiresLogin’] option is set and the user is not logged in, you can use wp_redirect() to redirect to the URL of your choice.

  12. barbara schendel
    barbara schendel March 26, 2015 at 12:31 pm

    This gets me close to what I need, thank you! One question — if it skips registration, will it still promote the person’s user role? My form charges money and promotes them to a different user role. Still need this if user is already logged in. (and I would like to not have to create two separate forms if possible since that just seems so inelegant!) Thanks!

    Reply
    1. David Smith
      David Smith Staff March 26, 2015 at 10:52 pm

      Not quite. With this, either a user is created or nothing. It sounds like what you want is the Update User feed; however, the User Registration add-on won’t let you have a Create feed and an Update feed on the same form. In this case, you might consider using this snippet to promote the user if they’re logged in based on a field value:

      https://gist.github.com/spivurno/22d12bb094e0d939ec22

  13. Rochel
    Rochel August 11, 2014 at 1:32 pm

    I’m not sure if this solution would work for me and I’m hoping someone can help me tweak it or point me in the right direction. I have a gravity forms registration form for an annual event that is hooked up with paypal and charges a registration fee and creates a user account once the payment goes through.

    The problem is, that I have people returning to the event this year who need to pay a registration fee and need to update their info. through the registration form but their info is already associated with a wordpress user. I can’t disable the User Registration add-on because there are new people registering for the event using this same form and I need the form to go ahead and make them a user account. I’m also not sure I can create a separate form without confusing visitors and having them give up.

    Any ideas would be a big help.

    Thanks!

    Reply
    1. David Smith
      David Smith Staff August 11, 2014 at 8:10 pm

      Hi Rochel,

      The easiest way to do this will simply be using two different forms. I don’t think users will be too confused by a quick message at the top of the form along the lines of “If you’re already a member, please renew here.” You could take it a step further and if they’re already logged in, just redirect them to the renewal form if they try to access the the registration form.

      The real benefit of using two separate forms is that you can use the User Registration add-on to handle updated the existing user on the renewal form to indicate that their account is good for another year. You could do this with a single form but it would be have to be custom coded.

  14. jochen
    jochen November 21, 2013 at 5:00 pm

    That’s cool, thanks for sharing!!!

    Is there a way to use the information if a user is logged in on other form conditionals???

    Thx

    Reply
    1. David Smith
      David Smith Staff November 22, 2013 at 1:41 pm

      You can use the {user:meta_key} merge tag in any Default Value field and then apply conditional logic based on that populated field to handle other form conditions.

    1. David Smith
      David Smith Staff June 1, 2012 at 9:52 am

      Hi Andy, looks like I missed something pretty obvious. Overriding the validation! The snippet has been updated. Give it a shot. :)

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

Skip User Registration For Logged In Users

This field is for validation purposes and should be left unchanged.