on my wordpress site I installed Gravity Forms. To have the form create an ID I placed this code in the child theme:
add_filter("gform_field_value_uuid", "get_unique");
function get_unique(){
$prefix = "VFI"; // 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 = 1; // update to the form ID your unique id field belongs to
$field_id = 93; // 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;
}
This code is working and it's not giving me much trouble. Since I pass all the info from gravity forms to mailchimp, I noticed on my Mailchiimp list that some of the Unique ID (eg: VFI819231) are replcated.
Before questioning its functionality, is there anything on this code that can cause this? Cause I'm doing some test, so creating an user then deleting it, then adding it again so I wonder if it's because this.
Thanks for helping!