Please Note: We are no longer using forums to facilitate standard support. 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.

Unique reference number for submissions

  1. pinman
    Member

    We want unique id numbers to be generated upon form submission. These need to be 10 digit including 3 digit prefix. I found http://www.gravityhelp.com/forums/topic/guid-entry-id and http://pastie.org/1398955 which works perfect apart from generating random numbers. We want numbers to be generated in incremental order rather than random numbers. I am not familiar with php, so can you please help.

    Posted 3 years ago on Tuesday December 6, 2011 | Permalink
  2. This isn't currently a built in feature.

    You were on the right track with the guid example, that is exactly what you want to do. However, because you want it incremental you would have to customize the guid code to suit your needs.

    Your custom code would need to query the existing entry data to get the last value that is present and then increment it, append it to the guid and then store it as the field value.

    This isn't something we have a tutorial or an example to point you to. It's a customization so you would have to write the code or hire a WordPress developer with Gravity Forms experience to write this type of customization for you.

    Posted 3 years ago on Tuesday December 6, 2011 | Permalink
  3. I am probably overlooking something obvious, but I've been forum-diving for an hour now and haven't found what I'm looking for... Carl, you reference (here and elsewhere) that we should "query the existing entry data to get the last value that is present and then increment it." I understand what we're trying to do, but I can't for the life of me figure out how to execute that query. How would I query for the most recent entry for a given form, in order to e.g. have the above GUIDs be incremented within different ranges for a specific form?

    Posted 3 years ago on Thursday January 19, 2012 | Permalink
  4. wilflare
    Member

    I have a request for this as well.. anyone can point us?

    Posted 3 years ago on Wednesday February 22, 2012 | Permalink
  5. wilflare
    Member

    i would love to self-code this. anyone could point us somewhere?

    Posted 3 years ago on Thursday February 23, 2012 | Permalink
  6. The code does not currently exist as a sample I can point you to. The closest thing to what is described is the thread mentioned in the original post:

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

    You'd have to take that code and modify it to accomplish the sequential capabilities.

    I'm not aware of any example code right now for querying entry data. I'll see if I can get one one of the developers on our team to come up with a code snippet to use as a starting point.

    Posted 3 years ago on Tuesday February 28, 2012 | Permalink
  7. 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;
    }
    ?>
    Posted 2 years ago on Tuesday November 27, 2012 | Permalink
  8. Thanks again for the code. I am going to close this topic because it is older, and refer people to your other post: http://www.gravityhelp.com/forums/topic/gravity-form-incremental-id-generation

    Posted 2 years ago on Tuesday November 27, 2012 | Permalink
  9. Gil Namur
    Member

    Hi!
    I am testing this code and have it ALMOST working.
    It's not generating the prefix.
    I am using the exact code (other than changing form and field ID's) for 2 forms.
    I am using uuid as the Parameter Name.
    What am I missing?
    Thanks and cheers,
    Gil

    Posted 2 years ago on Wednesday February 13, 2013 | Permalink
  10. Gil, have you seen this other recent post, maybe a little more simplified. You can read from this reply downward. http://www.gravityhelp.com/forums/topic/send-confirmation-number#post-145386

    Posted 2 years ago on Wednesday February 13, 2013 | Permalink
  11. Gil Namur
    Member

    Hi Chris,
    Thanks :-)
    I did look at it and that would work great for a single form but I have to do 3 different ones with different prefixes which is why I thought the code above looked promising.
    He never mentioned if he only used uuid for the parameter or added something to that for the prefix.
    Sooooooooo close LOL
    Cheers,
    Gil

    Posted 2 years ago on Wednesday February 13, 2013 | Permalink
  12. Did you make any more progress with this Gil?

    Posted 2 years ago on Sunday February 17, 2013 | Permalink
  13. Gil Namur
    Member

    Hi Chris,

    Nope. I'm stuck. Mind you, I have had a plethora of other things to do as well.
    Will leave you a question at the post you pointed me to. Oh wait! I cant ... it's closed.
    Question is - as you know I need multiple prefixes.
    If i added a second filter - same code but changed the value to uuid2 and then changed the prefix, would that work? (gform_field_value_uuid2)
    THANKS and cheers,
    Gil

    Posted 2 years ago on Monday February 18, 2013 | Permalink
  14. That approach would populate a different parameter in the same form, the parameter names uuid2. Is that what you want, or do you want a one prefix tied to one form, and each prefix will be different (one prefix for each form)?

    Posted 2 years ago on Monday February 18, 2013 | Permalink
  15. Gil Namur
    Member

    Hi Chris,
    Indeed ... one prefix (which becomes part of a unique PO#) for each form.
    Order Form 1 - PayPal sales) prefix PP-#####
    Order From 2 - COD sales) prefix COD-#####
    etc
    I thought that if I used the code you show here - http://www.gravityhelp.com/forums/topic/send-confirmation-number#post-145386 - and used uuid as the parameter for form 1 and uuid2 as the parameter for form 2 that would get me there?
    Cheers,
    Gil

    Posted 2 years ago on Monday February 18, 2013 | Permalink
  16. Gil Namur
    Member

    Hi Chris,
    Further to my note yesterday - using the code you have at - http://www.gravityhelp.com/forums/topic/send-confirmation-number#post-145386

    If I use your fist example, it faithfully returns a number, but no prefix.
    If I use the last bit of code in that thread, it returns the prefix, but no number.
    Just doing this on one form, using your exact code.
    Cheers,
    Gil

    Posted 2 years ago on Tuesday February 19, 2013 | Permalink
  17. Gil, I revised the code a little bit later in that topic:
    http://www.gravityhelp.com/forums/topic/send-confirmation-number#post-145509

    The $prefix was not working correctly, so I hard coded it. Please try this code.

    Posted 2 years ago on Tuesday February 19, 2013 | Permalink
  18. Gil Namur
    Member

    Hi Chris,
    I DID try that code. Exactly as you have it there. ( I referred to it as the last bit of code).
    It returns a prefix, but no number. I just tried it again. Same result.
    I am assuming that all I need to enter in the hidden field for Parameter Name is uuid - correct?
    Cheers,
    Gil

    Posted 2 years ago on Tuesday February 19, 2013 | Permalink
  19. Hi Gil,

    Sorry took long to respond

    here is the full code i had and its working.

    the problem is need to do the switch code inside the do while loop

    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;
    
        case 13:						//form ID
            $uuid['field_id'] = 28;		//field ID on the form
            break;
    
    	case 16:						//form ID
            $uuid['field_id'] = 2;		//field ID on the form
            break;
    
        case 10:						//form ID
            $uuid['field_id'] = 49;		//field ID on the form
            break;
        case 4:						//form ID
            $uuid['field_id'] = 30;		//field ID on the form
            break;
    
        case 1:						//form ID
            $uuid['field_id'] = 34;		//field ID on the form
            break;
    	case 5:						//form ID
            $uuid['field_id'] = 49;		//field ID on the form
            break;
    	case 7:						//form ID
            $uuid['field_id'] = 60;		//field ID on the form
            break;
    	case 8:						//form ID
            $uuid['field_id'] = 33;		//field ID on the form
            break;
    	case 3:						//form ID
            $uuid['field_id'] = 29;		//field ID on the form
            break;
    	case 2:						//form ID
            $uuid['field_id'] = 5;		//field ID on the form
    		print_r('aaa');
            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'];
    
    	global $wpdb;
    
        do {
    		$formid = $form_id; //get ID of the form
    
    		    switch($form_id) {
    
    			case 6:
    				$prefixs = "FOHSRF # - ";	//prefixs for different forms
    				break;
    			case 14:
    				$prefixs = "VSRF # - ";		//prefixs for different forms
    				break;
    			case 12:
    				$prefixs = "VSRF # - ";		//prefixs for different forms
    				break;
    			case 11:
    				$prefixs = "VSDEIF # - ";	//prefixs for different forms
    				//print_r($prefixs);
    				break;
    			case 13:
    				$prefixs = "FOHSRLR # - ";	//prefixs for different forms
    				break;
    			case 10:
    				$prefixs = "SMRF # - ";	//prefixs for different forms
    				break;
    			case 4:
    				$prefixs = "VTTCF # - ";	//prefixs for different forms
    				break;
    			case 1:
    				$prefixs = "EHF # - ";	//prefixs for different forms
    				break;
    			case 5:
    				$prefixs = "ELA # - ";	//prefixs for different forms
    				break;
    			case 7:
    				$prefixs = "IRF # - ";	//prefixs for different forms
    				break;
    			case 8:
    				$prefixs = "SIF # - ";	//prefixs for different forms
    				break;
    			case 3:
    				$prefixs = "RIF # - ";	//prefixs for different forms
    				break;
    
    			case 16:
    				$prefixs = "GHIRA # - ";	//prefixs for different forms
    
    				break;
    			case 2:
    				$prefixs = "CSF wewwe# - ";	//prefix for different forms
    				break;
    
    			}
    		$tables = $wpdb->prefix . 'rg_lead';
    		$form_count = $wpdb->get_var("SELECT COUNT(*) FROM $tables WHERE form_id = '$formid'");
    		//$date = date("d/m/Y");
    		//$form_count = RGFormsModel::get_form_counts($formid);
    
            $unique = $form_count + 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
    		$date = date('m-d-Y');
    
    		//print_r($date);
            $unique = $prefixs . $unique . ' - ' . $date; // prefixs and the unique number	//	
    
        } while (!check_unique($unique, $form_id, $field_id));
    	//print_r($unique);
        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;
    }
    Posted 2 years ago on Thursday February 21, 2013 | Permalink
  20. Gil Namur
    Member

    Hi drawonline :-)

    THANKS! I will try this today.
    Just to be clear on the cases. If I only have 2 cases, do I need the print_r('aaa');
    statement before the last break? Like this below.

    case 1: //form ID
    $uuid['field_id'] = 8; //field ID on the form
    break;
    case 2: //form ID
    $uuid['field_id'] = 8; //field ID on the form
    print_r('aaa');
    break;

    Thanks and cheers,

    Gil

    Posted 2 years ago on Thursday February 21, 2013 | Permalink
  21. Gil Namur
    Member

    Hi drawonline.

    This works perfectly!
    Thank YOU!!!!!

    Gil

    Posted 2 years ago on Friday February 22, 2013 | Permalink

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

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only