Documentation

gwp_generate_token

The gwp_generate_token merge tag for Gravity Forms is designed to generate a random token with customizable attributes such as length and character set.

How to Use the gwp_generate_token Merge Tag

The gwp_generate_token merge tag has the following possible parameters (default values are shown here):

{gwp_generate_token charset='AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890' length='16' prefix='' postfix='' unique='false' retries='10'}

Charset Parameter

Defines the set of characters that can be used to generate the token. By default this character set is used:

AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890

Length Parameter

Specifies the length of the generated token. This must be an integer with a minimum value of 8. If the provided length is less than 8 or not an integer, an error will be returned.

Prefix Parameter

Adds a specified prefix to the generated token.

Postfix Parameter

Adds a specified postfix to the generated token.

Unique Parameter

Determines whether the generated token should be unique. by default this is ‘false‘. When set to ‘true', the generated token will be checked for uniqueness against the entry_meta and draft_submissions database table. This will make sure there is no (draft) entry with this value at the moment the token is generated. Up to 10 attempts (or as specified in the retry parameter) will be made to ensure uniqueness before returning an error if unsuccessful.

Retries Parameter

Allows to change the number of retries to achieve uniqueness.

Examples

Example UsageExpected Output
{gwp_generate_token}A random token of 16 characters using the default character set.
{gwp_generate_token length=12}A random token of 12 characters using the default character set.
{gwp_generate_token charset=ABC123 length=10}A random token of 10 characters using only A, B, C, 1, 2, 3.
{gwp_generate_token length=20 unique=true}A random token of 20 characters ensured to be unique.
{gwp_generate_token prefix=PRE_}A random token prefixed with “PRE_”.
{gwp_generate_token postfix=_POST}A random token postfixed with “_POST”.

Last updated: 01-11-2024

Advanced Merge Tagsv1.7.1

To use the functionalities described in this documentation, you'll need to get the GravityWP - Advanced Merge Tags add-on.

Read more