I have multiple forms. Based on those forms I need a hidden field populated with a prefix and a sequential number. Each form has a hidden field. That field can be filled dynamically and has a paramater of 'uuid'.

I have the following code... any suggestions on how to change the following code? This snippet works but it uses a random number (mt_rand), I prefer [prefix]-00001, [prefix]-00002, etc.

In addition it would be even better when every form has his own prefix. But that beyond my php skills. Preferably sequential for every form, example:

Form A with a prefix 'prd' ([prefix]-00001)

  • prd-00001
  • prd-00002

Form B with a prefix 'lead' ([prefix]-00001)

  • lead-00001
  • lead-00002

Thanks for any thoughts and ideas. Keep in mind that my php skills are pretty basic.


add_filter("gform_field_value_uuid", "get_sequential_nr");
function get_sequential_nr(){
    $prefix = "set_prefix_here";
    do {
        $unique = mt_rand();
        $unique = substr($unique, 0, 5);
        $unique = $prefix . $unique;
    } while (!check_unique_nmbr($unique));
    return $unique;
function check_unique_nmbr($unique) {
    global $wpdb;
    $table = $wpdb->prefix . 'rg_lead_detail';
    $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;

1 Answer 1


Have you looked at the Gravity Forms Unique ID Wiz? This allows you to specify a prefix for each form that gets added to the Entry ID.

  • Actually yeah, I did just that a few days ago. Works great.
    – Kortschot
    Oct 29, 2018 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.