PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Gravity Form Incremental ID Generation

  1. hi all,

    Ive read from this post

    http://www.gravityhelp.com/forums/topic/guid-entry-id

    and i made an updated code for generating Incremental ID generation

    <?php
     add_filter("gform_pre_render", "process_unique");
    function process_unique($form) {
        global $uuid;
        $uuid['form_id'] = $form['id'];
    
    	switch($form['id']) {
    	case 6:							//form ID
            $uuid['field_id'] = 60;		//field ID on the form
            break;
    	case 14:						//form ID
            $uuid['field_id'] = 158;	//field ID on the form
            break;
    	case 12:						//form ID
            $uuid['field_id'] = 158;	//field ID on the form
            break;
        case 11:						//form ID
            $uuid['field_id'] = 34;		//field ID on the form
            break;
    
        }
    
        add_filter("gform_field_value_uuid", "get_unique");
        return $form;
    }
    
    function get_unique(){
        global $uuid;
    	$form_id = $uuid['form_id'];
        $field_id = $uuid['field_id'];
    
        switch($form['id']) {
    	case 6:
    		$prefix = "FOHSRF # - ";	//prefix for different forms
            break;
        case 14:
    		$prefix = "VSRF # - ";		//prefix for different forms
            break;
    	case 12:
    		$prefix = "VSRF # - ";		//prefix for different forms
            break;
        case 11:
    		$prefix = "VSDEIF # - ";	//prefix for different forms
            break;
        }
    
        do {
    		$formid = $form_id; //get ID of the form
    		$form_count = RGFormsModel::get_form_counts($formid);
            $unique = $form_count['total'] + 1; // count of the lead form entries incremented by one
    		$unique = str_pad($unique, 3, '0', STR_PAD_LEFT); // padding for number format 001,002...015 so 3 digit number format
            $unique = $prefix . $unique; // prefix and the unique number
        } while (!check_unique($unique, $form_id, $field_id));
    
        return $unique;
    }
    
    function check_unique($unique, $form_id, $field_id) {
        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;
    }
    ?>

    hope this helps.
    cheers,

    Posted 11 years ago on Monday November 26, 2012 | Permalink
  2. Thanks a lot for posting your code. I'm sure that will prove useful to someone.

    Posted 11 years ago on Tuesday November 27, 2012 | Permalink
  3. Do you happen to have a site that is using this code for a visual of it?
    Thanks

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  4. Does this code generate something like a reference number?

    Posted 11 years ago on Sunday February 10, 2013 | Permalink
  5. I will close this topic because I provided an answer to a similar question here:
    http://www.gravityhelp.com/forums/topic/send-confirmation-number#post-145386

    Posted 11 years ago on Sunday February 10, 2013 | Permalink

This topic has been resolved and has been closed to new replies.