$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>functions - Add sequential number to a Gravityforms form|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - Add sequential number to a Gravityforms form

matteradmin8PV0评论

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.

Paul

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'");
    if(empty($result))
        return true;
    return false;
}

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.

Paul

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'");
    if(empty($result))
        return true;
    return false;
}
Share Improve this question edited Aug 1, 2018 at 12:29 Kortschot asked Aug 1, 2018 at 12:22 KortschotKortschot 1171 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

Post a comment

comment list (0)

  1. No comments so far