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.
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?
Hi Paul,
You can append the Form ID to the
gform_is_delayed_pre_process_feed
andgform_pre_process
filters to target only a specific form. Here’s an updated version of the snippet that instructions for targeting a specific form.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?
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,
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,
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,
hello how can use code? can i add the code in functions.php?
Hello Stephane, That is correct. You will be inserting this into your themes functions.php file. For more troubleshooting help, check out our help article here. 😀
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?
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.😁
Code is corrupt. Submit button disappears for multi-page forms
Never mind, this turned out to be theme specific
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?
Hi Fabienne, hm, I’m not sure I followed. Could you explain your end goal?
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?
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…
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.
[…] 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. […]
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
Hi Seb, I have a resource for updating by email on “Update” feeds but not on “Create” feeds: https://gist.github.com/spivurno/3bb450d5469df7b10f6d273a6cd24272
Hi David, thx.
I`ve just tested it. But it only says if user is not logged in: Email alreads exists.
Yeah, I realized after posting that there is some other code required to get this to work. Try adding this snippet as well.
https://gist.github.com/spivurno/c7ec7c871760e8e0ea5ed914d9fbfaf5
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
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
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?
This will help: https://gravitywiz.com/documentation/snippet-troubleshooting/
hi david, can you please advise how to make this code works when user is NOT logged-in?
Hi
This not working for me. Still getting email address already registered.
Are you using the latest version of the snippet above? Is the user actually logged in?
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?
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/
Is this snippet still working?. for version RC1 beta3.
For me, it is still showing the user field and asking for validation.
Hi Tuhin, yes, this is working on our end with the latest versions of Gravity Forms and GF User Registration.
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]
I posted on Pastie.org.
http://pastie.org/10638856
Hi Russell, I can’t confirm that this works but it might get you a little closer. The basic idea is that you can just check the $_POST for the submitted username rather than setting up another filter level via the get “gform_get_input_value” filter.
http://pastie.org/private/h8rd3bjcm92a4ym8raq#9,18
Thanks David! I’m still doing some testing, but that code seems to have done the trick!
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?
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.
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.
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!
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.
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!
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
Awesome! Thank you!
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!
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.
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
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.
Hi David,
Can this be combined with an auto login function as http://www.gravityhelp.com/forums/topic/auto-login-after-successful-completion-of-form
and
http://www.gravityhelp.com/forums/topic/user-registration-login-redirect-to-private-page#post-31529
so if the user is either not registered or not logged in they are given the same form and either registered and the form submitted or just submitted.
Thanks
Mark
This doesnt work. I pasted into functions.php and i still get email is already registered. pls help. thx
Hi Andy, looks like I missed something pretty obvious. Overriding the validation! The snippet has been updated. Give it a shot. :)