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:

  1. Username (with the username CSS class assigned)
  2. Email (with the email CSS class assigned)

Following the pattern, we’ll need to setup two hooks:

  1. Which fires during the form validation
  2. 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:

  1. Sanitize and store the $_POST superglobal array submitted form fields in the corresponding variables
  2. Verify if the username and email exist
  3. 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!

The following two tabs change content below.
WordPress Blogger, Certified Codeable Expert Developer, Senior WordPress developer. Having worked with WordPress for over 8 years creating plugins, themes and WordPress based applications. I am contributor, CodeCanyon creator and YouTuber.