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!
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:
- Gravity Forms
- Gravity Perks
- GP Unique ID
- GW_Value_Exists_Validation snippet
- About 10 minutes
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
- Step 2: Setup a Gravity Form Notification to deliver the reference number
- Step 3: Build Form B and setup the GW_Value_Exists_Validation snippet
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.
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.
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 submissiontarget_field_id
should be the ID of the field on Form B for which the reference number should be entered and validatedsource_form_id
should be the ID of Form A where the reference number is generatedsource_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!
This works great! Thank you for your wizardry. :-)
Hi Wendell,
Glad to hear it! 🪄
Hi David!
The issue is the Unique ID field isn’t coming up in the conditional logic for emails or for twilio add-on
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.
Hi Tommy, what is the issue you are experiencing? Also, for faster support, submit a ticket.
Hi David!
The issue is the Unique ID field isn’t coming up in the conditional logic for the twilio add-on.
I got this working just fine but there is a problem with the form showing “x” under the field even though it is correct when you submit.
Here is my form: https://www.bloomscpapclinic.com.au/home-sleep-test/booking/
The test validation requirements are: Code: SQRC906013606 Last Name: Carmody
Thanks so much!
Hi James, drop us a line via support and we’ll be happy to dig in: https://gravitywiz.com/support/
Thanks, will do. Could you please delete my comment so the link is taken off the internet.
That was the validation I used with your GW_Value_Exists_Validation snippet.
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.’ ) );
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.
Can you share a pastie of your snippet configuration code?
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
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. :)
[…] 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 […]