How to Generate and Validate a Reference Number for Gravity Forms with GP Unique ID

Generate a reference number on Form A and require this reference number on Form B in order to submit the form.

This article requires the GP Unique ID perk.

Buy Gravity Perks to get this perk plus 46 other premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

This tutorial will show you how to use Gravity Forms Unique ID to generate a reference number on one form then setup another form to confirm that the reference number is valid. Let’s get started!

Getting Started

This tutorial requires the following plugins and resources:

Now that you have installed and activated the above plugins and snippet let’s walk through each step?

Step 1: Build Form A and add the Unique ID Field

There will be two forms. Form A will handle generating the reference number. Form B will query Form A to make sure that the reference number entered is valid.

The only requirement for Form A is that it contains a Unique ID field. With GP Unique ID installed, you will see a new field available in the Form Editor under the “Advanced Fields” group.

gp-unique-id-add-field-buttonGP Unique ID Field Button

Add this field to your form and save the form. The Unique ID field is a hidden field so will not display on the front-end.

For a comprehensive understanding of all the options available with GP Unique ID, visit the GP Unique ID documentation.

Step 2: Setup a Gravity Form Notification to deliver the reference number

Note: The demo provides the reference number in the confirmation. This was for the sake of simplicity. We recommend sending the reference number via email so the user will always have a copy of it. You could also include it in the confirmation.

Next, visit the Form’s Notifications page. Add a new notification. We’ll assume you are collecting the user’s email address via an Email field on the form. You can configure the notification to be sent to this email address via the “Send To” setting.

You can include the generated reference number in the notification by finding the Unique ID field in the merge tag list (appears to the right of the “Message” setting). Clicking this item will insert the merge tag into the message. When the notification is sent, this merge tag will be replaced with the generated unique ID, which, in this case, is acting as a reference number for the submission.

reference-number-emailAdd the Unique ID merge tag to a Gravity Forms Notification

Step 3: Build Form B and setup the GW_Value_Exists_Validation snippet

Now that we have Form A generating the reference number, we can build Form B which will use a Gravity Wiz snippet to require a reference number in order to submit the form.

Build Form B based on your needs but make sure to include a Single Line Text field where the user will enter their reference number. If an invalid reference number is entered, this field will also display an error message indicating the failure.

Go ahead and following the installation instructions on the GW_Value_Exists_Validation. A few tips for configuring this snippet:

  • target_form_id should be the ID of Form B where the reference number is required for submission
  • target_field_id should be the ID of the field on Form B for which the reference number should be entered and validated
  • source_form_id should be the ID of Form A where the reference number is generated
  • source_field_id should be the ID of the Unique ID field on Form A by which the reference number is generated

That’s it!

How’d we do?

If you found this tutorial helpful, let us know. Also, we’d love to hear other ways that you have used GP Unique ID so we can share the knowledge with others. Thanks!

Comments

  1. Tommy
    Tommy January 14, 2020 at 12:22 am

    Hi! We are having an issue when trying to use the unique ID with conditional logic (for notifications and for twilio). We essentially are creating a round robin between two emails and phone numbers so all odd Unique IDs go to one employee and all even Unique IDs go to another employee.

    Reply
    1. Tommy
      Tommy January 31, 2020 at 1:07 am

      Hi David!

      The issue is the Unique ID field isn’t coming up in the conditional logic for the twilio add-on.

  2. Philip
    Philip June 12, 2015 at 5:04 pm

    Yes, here it is:

    // Broker = Source; Equipment = Target new GW_Value_Exists_Validation( array( ‘target_form_id’ => 6, ‘target_field_id’ => 3, ‘source_form_id’ => 2, ‘source_field_id’ => 18, ‘validation_message’ => ‘Hey! This isn\’t a valid reference number.’ ) );

    // Agent = Source; Equipment = Target new GW_Value_Exists_Validation( array( ‘target_form_id’ => 6, ‘target_field_id’ => 3, ‘source_form_id’ => 1, ‘source_field_id’ => 20, ‘validation_message’ => ‘Hey! This isn\’t a valid reference number.’ ) );

    Reply
  3. Philip
    Philip June 12, 2015 at 1:26 pm

    Hi David, I tried to use this method with 2 forms. I generated Unique ID’s for 2 different registration forms (Agent & Broker), then tried to use those ID’s to validate in the same set of forms (Equipment, Metals, Property, Structure). When Agents and Brokers register on our site, we want their Unique ID’s generated at registration, to be validated when submitting referral forms (Equipment, Metals, Property, Structure). I got the ID validation to work for the first set of forms (registration), but not the second (referrals).

    I followed your instructions for applying class-based snippets to different forms. I’m not sure if I’m doing something wrong, or if I have to use another method to make this work. Can you please advise me on this?

    Thanks.

    Reply
  4. Weird Mike
    Weird Mike June 8, 2015 at 11:04 pm

    I would like to know if I could use this on 3 different forms or if it’s just limited to one form ID only. Also, I would like to ask how I could generate a link that Dynamically Populates the Unique ID field.

    If I have to purchase GP in order to get this answered correctly and timely I will purchase it now. -Thanks

    Reply
    1. David Smith
      David Smith Staff June 9, 2015 at 11:36 am

      Hi Mike, you can use this on as many forms as you’d like. The Unique ID field cannot be dynamically populated because it is generated per entry when the entry is submitted. If you’re asking how you would dynamically populate the field on the form that must be validated against a Unique ID field on another form, there are a variety of ways. Let me know if I can answer any more questions. :)

  5. Weekly Roundup: January 23, 2015 – Sell with WP January 23, 2015 at 2:01 am

    […] Wiz posted a couple of new Gravity Forms tutorials this week: how to generate and validate a reference number from your form, and how to require this value to submit another […]

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Grab a bundle of free Gravity Forms plugins

Enter your email and receive our most popular free plugins and snippets, plus access to hundreds of others.

This field is for validation purposes and should be left unchanged.