In my ongoing love for Gravity Forms, I was using the plugin this morning to add some functionality to my WordPress maintenance service, The WP Butler.
When a new member signs up, they’re immediately asked to complete a short form about their site, so that I can get access to it above all else. So if a user completes payment but for some reason doesn’t complete that form, that’s an issue, as they’ll be paying for a service that I can’t perform.
So I wanted to notify them if they hadn’t completed this particular form. The idea was to have a big red box at the top of the Members Area with a warning, referring them to the form so that they could provide the needed information.
Here’s how I did it:
Add a hidden field to the form
I started by taking the form that I had already built and added a checkbox field to it. I left just one option (Yes) and labelled it “Completed this form”. Then I pre-checked the box and set the visibility to “Admin Only”.
Now, whenever the form is submitted, the user will not see the field, but the response will always be Yes, because we pre-checked the box.
Add value to user profile
Now we want to add a piece of usermeta to the user’s profile, so that there is a permanent record of whether that form was completed for each user. To do this, I used the Gravity Forms User Registration add-on. This requires a developer license, so again I reiterate that you should get a Gravity Forms Developer license.
Create a new feed under Forms > User Registration, select Update User as your action and select the form that you added the checkbox to. At the bottom of the ensuing form is a section called User Meta. For Select Meta Option, choose Add Custom from the bottom of the list and enter a descriptive name in the text field that it brings up. Then select the Yes checkbox in the next dropdown, so that when that box is checked (always), it will be saved against the user’s profile in a field that you just labeled.
Create a shortcode for notifying user
Now that we’ve got the mechanism for determining whether a user has completed the form, we want to notify them if they haven’t.
Here’s the code that I drew up:
This code starts off by getting the current user’s info from the database. Then it takes the value of the completed_new_member_info field (or whatever you called your field). Then, we use a conditional to say that if the user has not completed the form (the value of the field is not “Yes”), then to return the contents of the shortcode. You’ll notice that I also used the do_shortcode function in doing so, so that I could nest a shortcode inside this shortcode that we’re creating.
Now you have a shortcode that you can put content (including shortcodes) inside, which will only show if the user has not completed the form.
Using the shortcode
I created a section at the top of my Members Area and used Symple Shortcodes to create a red box that would display if the user hadn’t completed the form, using this syntax:
If a user hasn’t completed the form, this is what they’ll see:
I’ve found this immensely useful, as now I can prominently display that reminder, without annoying people who have already completed the form. I’d be interested to see how other people have used this snippet.