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.

GUID? Entry ID?

  1. Pete Bernardo
    Member

    Just a suggestion, it would be nice if GF could generate a Unique ID per entry... ala an order number

    Posted 15 years ago on Monday December 28, 2009 | Permalink
  2. This can be accomplished now using a hidden field and api hook to pre-populate the value but it would make it easier for users to add a unique id to their entries if we made an advanced field that did it for them. Thanks for the suggestion!

    Posted 15 years ago on Monday December 28, 2009 | Permalink
  3. anthonys
    Member

    Id like to see this too.

    Any pointers on how to do it via a hidden field and API hook?

    Posted 14 years ago on Monday March 15, 2010 | Permalink
  4. Lee Hord
    Member

    I had a need to do something like this and so I put this together:

    add_filter("gform_field_value_uuid", "uuid");
    function uuid($prefix = '')
     {
        $chars = md5(uniqid(mt_rand(), true));
        $uuid  = substr($chars,0,8) . '-';
        $uuid .= substr($chars,8,4) . '-';
        $uuid .= substr($chars,12,4) . '-';
        $uuid .= substr($chars,16,4) . '-';
        $uuid .= substr($chars,20,12);
        return $prefix . $uuid;
      }
    1. 1. Add this code to your functions.php file.
    2. 2. Create your form and add a hidden field and allow it to be populated dynamically (advanced tab).
    3. 3. Type "uuid" in the parameter name text field.
    Posted 14 years ago on Monday March 15, 2010 | Permalink
  5. Playing with this for awhile, how can I shorten this to 8 digits plus a unique prefix? Basically I need a number that looks like this for each entry into the forms:

    BDWA12345678
    BDWA23456789
    etc....

    Thanks for any help

    Posted 14 years ago on Tuesday December 21, 2010 | Permalink
  6. Hi Ryan,

    I was a little confused by your example of how you wanted the number formatted. Which option are you looking for?

    1. Both the prefix and 8 digits would be random.
    2. The prefix is constant and the 8 digits are random.
    3. The prefix is constant and the 8 digits are incrementing

    Let me know and I'll cook something up for you.

    Posted 14 years ago on Tuesday December 21, 2010 | Permalink
  7. sxmungall
    Member

    This sounds like something I could really use...

    Is there any way of getting GF to email the ID out on the "Notification to User" email? And instead of generating a random number, could it scroll through a list of predefined IDs. That way it could be used to perhaps send out a serial number, only once per completed form?

    Posted 14 years ago on Wednesday December 22, 2010 | Permalink
  8. @sxmungall Any field values you store can be emailed out in the Notification to User. All fields are available from the Insert form fields drop down when editing your Notifications, and it would automatically be included when using the All_Fields variable. So yes, if you create a GUID and store it in a hidden field it could be included in notifications.

    Posted 14 years ago on Wednesday December 22, 2010 | Permalink
  9. The first digits would be the same across all fields: BDWA(8 random digits or incremental)

    What I do need is unique numbers, so if they are random, I need to make sure that we don't get repeats.

    thanks for your help?

    Posted 14 years ago on Wednesday December 22, 2010 | Permalink
  10. Dave will be replying back soon with a code sample.

    Posted 14 years ago on Wednesday December 22, 2010 | Permalink
  11. Building on Lee's solution, here is an update that should meet your requirements Ryan.

    http://pastie.org/1398955

    You can implement this the same way you did Lee's. In addition, you'll need to update three items:

    • The prefix on line 7 of the example
    • The form ID on line 22
    • The field ID on line 23

    When attempting to get a unique random number, the more digits you use the easier it becomes. Using only 8 digits, it is probably ideal to actually check the database to ensure that the random number generated is unique. The solution I've provided will continue generating random numbers until a number unique to your field has been verified.

    Hope this helps!

    Posted 14 years ago on Wednesday December 22, 2010 | Permalink
  12. wow thanks, I'll look at this

    Posted 14 years ago on Thursday December 23, 2010 | Permalink
  13. Question:
    I have 5 forms that need these numbers
    in these instances:

    The form ID on line 22
    The field ID on line 23

    Can I add more than one?

    Posted 14 years ago on Thursday December 23, 2010 | Permalink
  14. Also can't find out what the "field id" is...no where is there a number listed.

    Finally is the "parameter name" "unique" or "get_unique"

    sorry for the easy questions! :)

    Posted 14 years ago on Thursday December 23, 2010 | Permalink
  15. Hi Ryan,

    Unfortunately, the gform_field_value_$parameter_name doesn't pass any information about which form you are on. With that said... to get this information, the solution gets a little more complicated.

    http://pastie.org/1401609

    case 7:

    Update these lines to the IDs of the forms you'll be generating the uuid's for.

    $uuid['field_id'] = 1;

    Update these to the field IDs for each form you'll be generating the uuid's for. You can view the HTML of the generated form to get the field ID of that form http://grab.by/82YB. In that screenshot the ID of that field would be 5.

    add_filter("gform_field_value_uuid", "get_unique");

    The paramater would be uuid. You can update this if you'd like by changing the value that follows the gform_field_value_ in the filter name.

    That's it. Paste all this in your functions.php file and you've got uuid magic.

    Posted 14 years ago on Thursday December 23, 2010 | Permalink
  16. Thanks it works Almost perfectly. In the HTML view it shows that a number with a prefix was given to the response. While in the "entries" area the prefix is missing. An if I click on a response it also show's no prefix, just the number.

    Thanks though, this is great!!!

    Posted 14 years ago on Thursday December 23, 2010 | Permalink
  17. Gil Namur
    Member

    Hey thanks from me too David and Lee!

    This is exactly what I needed!

    Cheers,
    Gil

    Posted 13 years ago on Monday February 21, 2011 | Permalink
  18. @Gil BTW The latest development release on the Downloads page contains the fix for the server path issue with the redirect to login problem you had been encountering if you want to install the latest.

    Posted 13 years ago on Monday February 21, 2011 | Permalink
  19. Gil Namur
    Member

    Thanks Carl!

    Will also want to get back to the image insert thing (post URL vs file URL) at some point but I have lots on my plate right now.

    Cheers,
    Gil

    Posted 13 years ago on Monday February 21, 2011 | Permalink
  20. ssbsupport
    Member

    "it would make it easier for users to add a unique id to their entries if we made an advanced field that did it for them. Thanks for the suggestion!"

    Did this ever happen? I don't see it anywhere so I'm guessing not - but if it did and I'm overlooking it please let me know!
    Thanks!

    Posted 13 years ago on Wednesday April 13, 2011 | Permalink
  21. thanks for the posts. I was wondering if it is possible to have two seprate Prefixes for two different choices. For example I want someone to either choose A or B, I would like the a different prefix to show up before each set of random numbers specific to the selection. I'm not sure if I'm approaching this correctly. I realize I need unique numbers to be generated without any repeats. The Prefix and Number is for upload identification purposes. I tried editing but keep getting errors. http://www.pastie.org/2250073

    thanks.

    Posted 13 years ago on Thursday July 21, 2011 | Permalink
  22. I found a work around, such an awesome plugin. Thanks.

    Posted 13 years ago on Thursday July 21, 2011 | Permalink

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