Need Code Snippet for Unique ID (Compatible with PHP 8.1) [RESOLVED]

Good Day!

We’re currently using a code snippet to generate Unique IDs for various forms throughout our website. It works great with one small caveat … it does not work when switching to PHP 8.1 or higher.


(1) Would anyone here know of a code snippet that can generate a Unique ID that is compatible with PHP 8.1? We prefer not to install another plugin.

(2) Is Gravity Wiz Unique ID compatible with PHP 8.1?

Thank you!

Would the forms entry id not work for you? See Entry ID summary

Hi Jonathan,

Dario from Gravity Wiz here.

GP Unique ID should be compatible with PHP 8.1

What’s your use case about?



Hi Derek,

Not sure that would work for our application.

Our code is used such that every time someone sends us an email, they receive an email confirmation notice with a unique ID in the email subject line. The unique ID is incremental for every email received and confirmed.

Can the forms entry ID do that? If so, can you be more specific on how to use the code?


Hi Dario,

Thanks for the reply. You said should. Is that confirmed? When using our code snippet and switch to PHP 8.1, all pages containing a Gravity Form break.

Use case explained above in my reply to Derek.

Thank you!

If by when the client sends you an email it is an admin notification sent to you then yes you would just need to add the entry Id merge tag to the subject line or to the body of the message.

I think Gravity Wiz Unique ID perk is one of the better options out there for that part of your use case, but I wonder if you are also encountering issues with either entry bloat (1 entry per reply) or a lack of context for your staff in viewing/replying to customers b/c each reply/unique ID is a separate entry?

Depending on how you are currently handling the email-to-entry creation piece (Zapier?) there may be some approaches involving Gravity Flow to have the interactions consolidate within one entry and improve the various user experiences as a result. Perhaps where a User Input steps with discussion field triggers the gravityflow_step_complete action to re-generate the unique ID? If you can share a few more details about how the entries are created, I should be able to put together a quick demo that highlights how similar could leverage a workflow for a more automated overall process.

Jamie (Gravity Flow)


1 Like

Hi Jamie,

First of all, Happy New Year!

Thanks for your kind input. We’re using the Code Snippet provided here. Works well for us, although it appears it’s not compatible with PHP 8.1.X. Not a biggie at this point, but eventually will be as our host adopts (and enforces) it.

To see the code snippet in action, visit this page and click on the button titled, “GET STARTED.” Fill out the form and wait for the confirmation message.

And yes, we’re also seeing some bloat in the backend (database). We’ll also have to address this soon as we receive more customer inquiries.

Hope this helps. Again, thank you.

1 Like

@JamieO and @dario,

Thank you so much for your input and recommendation. Gravity Wiz Unique ID should satisfy our needs.

However, before we spend $$$ to test drive Unique ID, is their any chance you guys can “tweak” the code provided below to make it compatible with PHP 8.1? It works well for us up to PHP 8.1.

Code Source (Gravity Forms): Create a Unique ID for Gravity Forms Entries

Thank you,


/* Put a unique ID on Gravity Form (single form ID) entries.
add_filter("gform_field_value_uuid", "get_unique");
function get_unique(){
    $prefix = "SLP2017-"; // update the prefix here
    do {
        $unique = mt_rand();
        $unique = substr($unique, 0, 8);
        $unique = $prefix . $unique;
    } while (!check_unique($unique));
    return $unique;
function check_unique($unique) {
    global $wpdb;
    $table = $wpdb->prefix . 'rg_lead_detail';
    $form_id = 3; // update to the form ID your unique id field belongs to
    $field_id = 7; // update to the field ID your unique id is being prepopulated in
    $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");
        return true;
    return false;

If you want to fix this snippet, you’ll need to know which part is not working. For doing that, I recommend using the built in Gravity Forms logging:

Once logging is enabled, add some logging statements to see if the variables and results are what you expect them to be:

Looking at the code, it seems pretty simple (and old), and adding logging statements will allow you to figure out which part is not working, but right off the bat, I think it’s odd that the table name they are using is rg_lead_detail. That is from Gravity Forms versions prior to 2.3 and no longer exists. The code does not use our API to get values from the entry table, which makes the hard-coded table name a problem.

Adding custom logging statements is the best way to approach this non-working code. If you decide to do that, please share the new code with the logging statements you added, and then a link to your log file, so we can check the log for your logging statements, if you need assistance figuring this out. Thank you.


Hi @chrishajer,


Issue solved (see below). Thank you.

Your information led me to this article (you guys need to hire Amy) which, in turn, provided what I needed to solve our issue.

Solution (options) provided below tested with PHP 8.1.2. No console errors, no functionality errors. Unique IDs generated without a glitch. Flying high!

I owe you a cold beer and a mega-size steak. Next time you’re in Dallas, please let me know.




Option 1:

Replace this line of code:

$table = $wpdb->prefix . 'rg_lead_detail';

With this line of code:

$table = $wpdb->prefix.'wp_gf_entry_meta';

(where ‘wp_’ represents the actual database table prefix we’re using. Omitted here for security reasons)

Option 2: (API Solution, Preferred)

Replace this line of code:

$table = $wpdb->prefix . 'rg_lead_detail';

With this line of code:

$table = GFFormsModel::get_entry_meta_table_name();

1 Like