Forgetting passwords is a common problem for website users. As a website owner, it is important to have a forgot/reset password functionality in place to ensure that your users can regain access to their account. Gravity Forms is a popular WordPress plugin that can be used to create custom forms, including a Forgot/Reset Password form. Using this method allows users to keep their frontend forms with their own brand.

In this article, we will guide you through the process of creating a Forgot/Reset Password form with Gravity Forms.

Step 1: Create a new form in Gravity Forms

The first step is to create a new form in Gravity Forms specifically for the Forgot/Reset Password functionality. Add the necessary fields to the form (an email field) and a submit button. You can quickly download the JSON form and import it into Gravity Forms. We’ve also pasted it below for your convenience:

{"0":{"title":"Forgot Password","description":"","labelPlacement":"top_label","descriptionPlacement":"below","button":{"type":"text","text":"Reset my Password","imageUrl":"","conditionalLogic":null},"fields":[{"type":"email","id":1,"formId":6,"label":"Email","adminLabel":"","isRequired":true,"size":"large","errorMessage":"","visibility":"visible","inputs":[{"id":"1","label":"Enter Email","name":"","autocompleteAttribute":"email","defaultValue":"","placeholder":"e.g. [email protected]"},{"id":"1.2","label":"Confirm Email","name":"","autocompleteAttribute":"email","defaultValue":"","placeholder":"e.g. [email protected]"}],"autocompleteAttribute":"email","description":"","allowsPrepopulate":false,"inputMask":false,"inputMaskValue":"","inputMaskIsCustom":false,"maxLength":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"","noDuplicates":false,"defaultValue":"","enableAutocomplete":false,"choices":"","conditionalLogic":"","productField":"","layoutGridColumnSpan":"","emailConfirmEnabled":true,"enableEnhancedUI":0,"layoutGroupId":"c8f43a5d","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"gppa-choices-filter-groups":[],"gppa-choices-templates":[],"gppa-values-filter-groups":[],"gppa-values-templates":[],"fields":"","displayOnly":""}],"version":"2.7.3","id":6,"markupVersion":2,"nextFieldId":2,"useCurrentUserAsAuthor":true,"postContentTemplateEnabled":false,"postTitleTemplateEnabled":false,"postTitleTemplate":"","postContentTemplate":"","lastPageButton":null,"pagination":null,"firstPageCssClass":null,"subLabelPlacement":"below","requiredIndicator":"asterisk","customRequiredIndicator":"(Required)","cssClass":"","buttonType":"text","buttonText":"Reset my Password","buttonImageURL":"","form_button_conditional_logic_object":"","form_button_conditional_logic":"0","saveButtonText":"Save and Continue Later","limitEntries":false,"limitEntriesCount":"","limitEntriesPeriod":"","limitEntriesMessage":"","scheduleForm":false,"scheduleStart":"","scheduleEnd":"","schedulePendingMessage":"","scheduleMessage":"","requireLogin":false,"requireLoginMessage":"","enableHoneypot":true,"validationSummary":false,"saveEnabled":"","enableAnimation":true,"save":{"enabled":false,"button":{"type":"link","text":"Save and Continue Later"}},"scheduleStartHour":"","scheduleStartMinute":"","scheduleStartAmpm":"","scheduleEndHour":"","scheduleEndMinute":"","scheduleEndAmpm":"","deprecated":"","gwreloadform_enable":"0","gwreloadform_refresh_time":"","gwreloadform_preserve_previous_values":"0","legacy":"","customJS":"","feeds":{"gravityformsadvancedpostcreation":[]},"notifications":[{"id":"6308c4ad6f7c6","name":"Password Reset","service":"wordpress","event":"form_submission","toType":"field","toEmail":"","toField":"1","routing":null,"fromName":"","from":"{admin_email}","replyTo":"{admin_email}","bcc":"","subject":"Your password reset instructions","message":"Hi {full_name},\r\n\r\nYou (or someone else) has requested a password reset for your account. If this was a mistake, you can ignore this email.\r\n\r\nTo reset your password, visit the following address: {password_link}","disableAutoformat":false,"notification_conditional_logic_object":"","notification_conditional_logic":"0","conditionalLogic":null,"to":"1","cc":"","enableAttachments":false}],"confirmations":[{"id":"613231f2d48cc","name":"Default Confirmation","isDefault":true,"type":"message","message":"Thank you. An email will be sent shortly. Please check your email (including Junk\/Spam) for the reset link.","url":"","pageId":"","queryString":"","event":"","disableAutoformat":false,"page":"","conditionalLogic":[]}],"honeypotAction":"spam"},"version":"2.7.3"}

Step 2: Add the Forgot/Reset Password functionality to Gravity Forms

To add the functionality to Gravity Forms, you need to add two filters to your theme’s functions.php file or a custom plugin file. The filter hooks into Gravity Form’s notifications system and generates a password reset link for the user.

In the code example below, your form ID is 99 and the email field ID is 1. If you import the form using the JSON above, you’ll need to change the Form ID.

// Validate Forgot Password
add_filter('gform_field_validation_99_1', function($result, $value, $form, $field) {

    $User = get_user_by('email', $value[0]);
    if(!$User->ID && $result['is_valid']===true)
    {
        $result['is_valid'] = false;
        $result['message'] = 'That email address does not exist in our system.';  
    }
    
    return $result;

}, 10, 4);

// After forgot password submission
add_filter('gform_notification_99', function($notification, $form, $entry) {

    // Send the forgot password email
    $user = get_user_by('email', rgar($entry, '1'));
    
    if($user->ID)
    {
        $displayName = $user->display_name;
        $reset_link = add_query_arg([
            'key' => get_password_reset_key($user),
            'action' => 'rp',
            'login' => urlencode($user->user_login)
        ], site_url('wp-login.php'));

        $notification['message'] = str_replace('{full_name}', $displayName, $notification['message']);
        $notification['message'] = str_replace('{password_link}', $reset_link, $notification['message']);
    }

    return $notification;

}, 10, 3);

Step 3: Customize the email template

Once the user submits the Forgot/Reset Password form, they will receive an email with a password reset link. You can customize the email template to include a message that provides instructions on how to reset the password. You can also customize the subject and sender of the email. If you didn’t download the JSON file in Step 1, navigate to the Notifications section of your selected form. Once there, you’ll need to add a new notification that sends to the user. We have an example below.

In step 2, we provided two variables that you can use in this email. {full_name} which is the display name of WordPress user and {password_link} which is the unique URL for this user to reset their password.

Gravity Forms notification settings for Forgot Password form

FREEBIE!

Got Gravity Forms? You'll need Cloudflare Turnstile.

Protect your forms from those pesky spammers with our Cloudflare Turnstile plugin for Gravity Forms. A super lightweight plugin.

Step 4: Show a confirmation message or redirect the user to a custom page

Once the user submits the Forgot/Reset Password form, you can either redirect them to a custom page that includes a message confirming the password reset link has been sent or simply display that message immediately. In our JSON example, we display it immediately.

Step 5: Test!

The next step is to test the form! This is the most important step. You should get all the way to the reset password screen of WordPress. Once you do, you know it’s working 100%!

Step 6: Read part 2

We recently published part 2 of this article, don’t forget to check it out because it handles a completely custom branded reset password page!