{"id":2007,"date":"2018-04-02T17:23:28","date_gmt":"2018-04-02T22:23:28","guid":{"rendered":"https:\/\/wpcodeus.com\/?p=2007"},"modified":"2025-07-30T10:59:05","modified_gmt":"2025-07-30T15:59:05","slug":"gravity-forms-create-a-unique-id-for-entries","status":"publish","type":"post","link":"https:\/\/wpcodeus.com\/gravity-forms-create-a-unique-id-for-entries\/","title":{"rendered":"Gravity Forms create a Unique ID for Entries"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"2007\" class=\"elementor elementor-2007\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-507408e e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"507408e\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-27d0b14 elementor-widget elementor-widget-text-editor\" data-id=\"27d0b14\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this tutorial we are going to show you how to make Gravity Forms create a unique ID for entries. Gravity Forms by default does not have a native function that allows you to create a unique ID or ticket number for each entry. The only type of ID Gravity Forms offer is the entry ID that starts from 1 and counts up. Maybe you want to have a and unique ID that is auto generated and formatted to something like this #46023. Well today we are going to show you how to do just that!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-f544937 e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"f544937\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d366703 elementor-widget elementor-widget-heading\" data-id=\"d366703\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Making Gravity Forms Create A Unique ID<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c8ee6c6 elementor-widget elementor-widget-text-editor\" data-id=\"c8ee6c6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Recently we were working on a website that was using Gravity Forms as a job entry system. The client wanted to have a unique ID attached to job entry that would be sent to them via a notification. To do this it is actually a very simple process by just adding a short bit of code to the functions.php file in their child WordPress theme. We though we would share it with you in-case any else ran into the same situation we have.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-70778c1 e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"70778c1\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-826dc52 elementor-widget elementor-widget-code-highlight\" data-id=\"826dc52\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-php line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp><?php\n\/* Put a unique ID on Gravity Form (single form ID) entries.\n----------------------------------------------------------------------------------------*\/\nadd_filter(\"gform_field_value_uuid\", \"get_unique\");\nfunction get_unique(){\n    $prefix = \"SLP2017-\"; \/\/ update the prefix here\n    do {\n        $unique = mt_rand();\n        $unique = substr($unique, 0, 8);\n        $unique = $prefix . $unique;\n    } while (!check_unique($unique));\n    return $unique;\n}\nfunction check_unique($unique) {\n    global $wpdb;\n    $table = $wpdb->prefix . 'rg_lead_detail';\n    $form_id = 3; \/\/ update to the form ID your unique id field belongs to\n    $field_id = 7; \/\/ update to the field ID your unique id is being prepopulated in\n    $result = $wpdb->get_var(\"SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'\");\n    if(empty($result))\n        return true;\n    return false;\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-096d4eb e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"096d4eb\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d9b533e elementor-widget elementor-widget-text-editor\" data-id=\"d9b533e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We are going to shout out to David from Gravity Wiz as he is the one who created this code snippet.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-6894a81 e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"6894a81\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-543b090 elementor-widget elementor-widget-heading\" data-id=\"543b090\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">A Few More Steps<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3ba9a4e elementor-widget elementor-widget-text-editor\" data-id=\"3ba9a4e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>What this code snippet does is it uses a Hidden Field (Advanced Tab Field). The script then puts your prefix if you\u2019ve added one, along with an unique ID. So now that you have added the code snippet about to your functions.php. Go to your form that you want to add the unique ID to and add a Hidden Field and add the Parameter Name listed below:<\/p><p>In the Parameter Name of your Hidden Field type,\u00a0<strong>uuid<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-5c84e42 e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"5c84e42\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-0ccd264 elementor-widget elementor-widget-image\" data-id=\"0ccd264\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"537\" src=\"https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Parameter-name-1-1024x537.jpg\" class=\"attachment-large size-large wp-image-2017\" alt=\"Gravity Forms create a Unique ID for Entries\" srcset=\"https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Parameter-name-1-1024x537.jpg 1024w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Parameter-name-1-300x157.jpg 300w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Parameter-name-1-768x403.jpg 768w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Parameter-name-1-700x367.jpg 700w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Parameter-name-1.jpg 1076w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-30192a8 e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"30192a8\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-86e9317 elementor-widget elementor-widget-text-editor\" data-id=\"86e9317\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"vc_row wpb_row section vc_row-fluid \"><div class=\" full_section_inner clearfix\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><div class=\"wpb_text_column wpb_content_element \"><div class=\"wpb_wrapper\"><p>Next, you can change the prefix on\u00a0<strong>line 6<\/strong>\u00a0of the code snippet to what you\u2019d like it to be.<\/p><\/div><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"vc_row wpb_row section vc_row-fluid \"><div class=\" full_section_inner clearfix\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><div class=\"wpb_text_column wpb_content_element \"><div class=\"wpb_wrapper\"><p>Now, change the Form ID on\u00a0<strong>line 21<\/strong>\u00a0of the code snippet to your form. In the picture below you can see ours is 3.<\/p><\/div><\/div><\/div><\/div><\/div><\/div><\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-9d36e2c e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"9d36e2c\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-398fa7c elementor-widget elementor-widget-image\" data-id=\"398fa7c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1024\" height=\"308\" src=\"https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Form-ID-1024x308.jpg\" class=\"attachment-large size-large wp-image-2023\" alt=\"Gravity Forms create a Unique ID for Entries\" srcset=\"https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Form-ID-1024x308.jpg 1024w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Form-ID-300x90.jpg 300w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Form-ID-768x231.jpg 768w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Form-ID-700x210.jpg 700w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Form-ID.jpg 1085w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ee8de64 elementor-widget elementor-widget-text-editor\" data-id=\"ee8de64\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>And last but not least, change the Field ID on\u00a0<strong>line 22<\/strong>\u00a0of the code snippet to the ID of the Hidden Field you just added. In the example below that ID is 33.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-13aaf4c e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"13aaf4c\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-9389689 elementor-widget elementor-widget-image\" data-id=\"9389689\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1013\" height=\"167\" src=\"https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Field_ID.jpg\" class=\"attachment-large size-large wp-image-2024\" alt=\"Gravity Forms create a Unique ID for Entries\" srcset=\"https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Field_ID.jpg 1013w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Field_ID-300x49.jpg 300w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Field_ID-768x127.jpg 768w, https:\/\/wpcodeus.com\/wp-content\/uploads\/2018\/04\/Field_ID-700x115.jpg 700w\" sizes=\"(max-width: 1013px) 100vw, 1013px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-5e02059 e-flex e-con-boxed parallax_section_no qode_elementor_container_no e-con e-parent\" data-id=\"5e02059\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-c1b92f1 elementor-widget elementor-widget-heading\" data-id=\"c1b92f1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">In Summary<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8b40cff elementor-widget elementor-widget-text-editor\" data-id=\"8b40cff\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>If you followed the steps above correctly you should now have a hidden field that makes Gravity Forms create a unique ID for each entry. If you are having any issues, leave a comment below and we will try to help you out as best as we can! We hope that you found this blog article and David from Gravity Wiz\u2019s code snippet was useful to you. If you want a more advanced version of this code snippet check out the WordPress Plugin called\u00a0<a href=\"http:\/\/gravitywiz.stfi.re\/documentation\/gp-unique-id\/?sf=djjbdwx\" target=\"_blank\" rel=\"noopener nofollow\">Gravity Form Unique ID<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Gravity Forms by default does not have a native function that allows you to create a unique ID or ticket number for each entry. The only type of ID Gravity Forms offer is the entry ID that starts from 1 and counts up. Maybe you want to have a and unique ID that is auto generated and formatted to something like this #46023. Well today we are going to show you how to do just that!<\/p>\n","protected":false},"author":1,"featured_media":2027,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[249,68],"tags":[71,73,69],"class_list":["post-2007","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-tutorials","category-code-snippets","tag-functions-php","tag-gravity-forms","tag-wordpress"],"acf":[],"_links":{"self":[{"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/posts\/2007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/comments?post=2007"}],"version-history":[{"count":0,"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/posts\/2007\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/media\/2027"}],"wp:attachment":[{"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/media?parent=2007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/categories?post=2007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpcodeus.com\/wp-json\/wp\/v2\/tags?post=2007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}