Welcome to the second part of the Gravity Forms Front End Login / Register / Edit account series.
In our previous tutorial we have created a simple Gravity based login form. In this tutorial we’ll cover the user registration form.
Part 2Ā – creating a simple register page
Similarly to the previous form let’s go ahead and create a form with two simple fields:
- Username (with the usernameĀ CSSĀ class assigned)
- EmailĀ (with the email CSS class assigned)
Following the pattern, we’ll need to setup two hooks:
- Which fires during the form validation
- Which fires during the form submission
Gform pre submission hook
This hook fires before the form has been submitted, but after the values have been validated.
Let’s see the code we’ve used for that part:
This hook will do the following:
- Sanitize and store the $_POST superglobal array submitted form fields in the corresponding variables
- Verify if the username and email exist
- If not – create a new user and notify him via email with his automatically generated password
Gform validation hook
Now, we can already register a new user, however the validation rules will not show up if we won’t create them! This means that the form can be submitted even if the specified data would conflict with the existing entries.
The following code will assure us that the form is validated properly:
The above hook is triggered separately for each of the form fields – this is why we need to rely on CSS class names, which we had created before.
This finishes the second part of our tutorial. The user registration is disabled for our site, hence we won’t be posting a working form this time!
Latest posts by RafaÅ Gicgier (see all)
- WP Doin Recognized among Top Web Developers in Poland - 29 October 2019
- WordPress application development ACF & Gravity Forms - 3 August 2019
- OptiPic.io – How and why to optimize the image on the site? - 8 April 2019