Just a suggestion, it would be nice if GF could generate a Unique ID per entry... ala an order number
Just a suggestion, it would be nice if GF could generate a Unique ID per entry... ala an order number
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!
Id like to see this too.
Any pointers on how to do it via a hidden field and API hook?
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;
}
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
Hi Ryan,
I was a little confused by your example of how you wanted the number formatted. Which option are you looking for?
Let me know and I'll cook something up for you.
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?
@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.
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?
Dave will be replying back soon with a code sample.
Building on Lee's solution, here is an update that should meet your requirements Ryan.
You can implement this the same way you did Lee's. In addition, you'll need to update three items:
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!
wow thanks, I'll look at this
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?
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! :)
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.
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.
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!!!
Hey thanks from me too David and Lee!
This is exactly what I needed!
Cheers,
Gil
@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.
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
"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!
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.
I found a work around, such an awesome plugin. Thanks.