Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Last active September 22, 2022 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anythinggraphic/346a6aad984f375429175eb552536cf6 to your computer and use it in GitHub Desktop.
Save anythinggraphic/346a6aad984f375429175eb552536cf6 to your computer and use it in GitHub Desktop.
Give each Gravity Forms entry a unique ID
<?php
/* 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'");
if(empty($result))
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment