Creating Multiple IDs with Gravity Forms
Dynamically generate multiple IDs for Gravity forms, which can be displayed on the form or provided to the user.
Have you ever needed to generate a unique IDs for a project? This could be to identify your users, generate raffle ticket numbers, or keep track of products.
Let’s take a look at how you can easily generate multiple IDs at once with Gravity Forms. You can then save these IDs to your database, use them in another form, or even share them with the user directly.
Getting Started
- Check requirements
- Make sure you have Gravity Forms installed and activated.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Make sure you have Gravity Forms installed and activated.
- Install the snippet
- Copy and paste the entire snippet into your theme’s functions.php file. Having trouble installing the snippet? Read this.
- Configure the snippet
- The basic configuration requires that you specify:
- the form that should be used to generate the ids (
form_id
). - the source field of the Unique ID on the form (
source_field_id
). - the field where the value should be saved to (
target_field_id
). - how many IDs you want to generate (
count
).
- the form that should be used to generate the ids (
- See the Usage Examples and available Parameters below.
- The basic configuration requires that you specify:
Usage Examples
Generate a Fixed Number of Unique IDs
new GPUID_Multiple_IDs( array(
'form_id' => 123,
'source_field_id' => 35,
'target_field_id' => 36,
'count' => 2
) );
Whenever form ID 123 is submitted, the Unique ID field 35 is used to create 2 new IDs. These IDs are stored in the target field 36.
Generate Unique IDs based on a Number Field
new GPUID_Multiple_IDs( array(
'form_id' => 123,
'source_field_id' => 1,
'target_field_id' => 2,
'count' => array(
'field_id' => 3,
),
) );
Whenever form ID 123 is submitted, the Unique ID field 35 is used to create new IDs. These IDs are stored in the target field 36. The number of IDs created is the value of field ID 3.
Generate Unique IDs based on a Dropdown Field
new GPUID_Multiple_IDs( array(
'form_id' => 123,
'target_field_id' => 36,
'source_field_id' => 35,
'count' => array(
'field_id' => 33,
'choices' => array(
'Hole in One Sponsor ($25,000)' => 12,
'Albatross Sponsor ($12,500)' => 8,
'Eagle Sponsor ($6,500)' => 4,
'Birdie Sponsor ($4,500)' => 2,
'Par Sponsor ($2,000)' => 1,
'Digital Media Sponsor ($1,000)' => 0,
'Chip-In Sponsor ($500)' => 0
)
)
) );
Whenever form 123 is submitted, the Unique ID field 35 is used to create new IDs. These IDs are stored in the target field 36. The number of IDs created depends on which option is selected from Dropdown Field 33.
For example, if Hole in One Sponsor ($25,000)
is selected, 12 IDs will be generated. If Par Sponsor ($2,000)
is selected, 1 ID will be generated.
Parameters
Here is a full list of the available parameters and additional information on how each can be configured.
- form_id (integer) (required)
The form ID which will be used to create Unique IDs on submission.
- source_field_id (integer) (required)
The field ID of the Unique ID field that will be used to create the IDs.
- target_field_id (integer) (required)
The field ID where the generated Unique ID(s) will be saved to.
- count (integer) (required)
A numeric value that determines how many Unique IDs get created. Supported values are:
Create coupons from Gravity Forms Submissions.
Want to give your users a discount? Check out our coupon creation snippet that dynamically creates coupon codes for Gravity Forms. Learn more here.