Changing Your Gravity Forms Field IDs
The easiest way to change your field IDs.
Getting Started
- Open the desired form in the Form Editor.
Open your Browser Console
Copy and paste this snippet into the console. Now the
gwChangeFieldId()
function is available for use on this page.Provide the current field ID and the new field ID to the
gwChangeFieldId()
function. Here is an example where current field ID is 4 and the new field is 12gwChangeFieldId( 4, 12 );
Click the “Update Form” button to save your changes.
Parameters
currentFieldId (int) (required)
The current field ID of the field for which you would like to change the ID.
newFieldId (int) (required)
The new field ID to which you would like to set the current field.
Any questions?
We’re always happy to answer questions. How does solution works for you? Why did you need to change your field IDs? Let us know in the comments below!
Lifesaving! Thanks a lot :)
Hi Agnes,
You’re welcome. Glad to know the snippet was useful to you.
Best,
This is amazing!! So helpful!
Thanks. Glad to know it’s helpful.
Hi, amazing solution. Very much needed to alter complex calculation fields and alter som input fields.
Still think it crazy this is not built in Gravityform UX itself! This is a developer solution, not a regular wp user solution. Any idea if there is a Gravity form add-on for this?
Hi Keesjan,
Glad it seems useful for you! We are not aware of any add-ons like this currently.
Best,
Is there something similar but change the acutal FORM ID (not the field)? Otherwise, this one worked great!
Hi Simon,
We currently do not have a snippet for this. I’ll pass this over to our developers to get their input. If we’re able to come up with a snippet, we’ll let you know by replying to this comment.
Best,
Hey Simon, best way to change a form ID would be do so directly in the database. Do you have access to your site’s database?
This is BRILLIANT. I have been wanting a tool for this for a long time!
I used a bit more geekery: (1) WPCLI and the Gravity Forms CLI plugin to dump my list of 200+ fields (it’s a big form) to a csv file. (2) With the help of a spreadsheet, I generated the “from” and “to” IDs for the function. I copied the whole column into the console all at once. It worked flawlessly.
For others coming later, be careful to avoid possible field number collisions!
If your form currently has these field IDs, 8, 2, 5, 3, 6
you can’t go directly to 1, 2, 3, 4, 5
8 -> 1 (OK) 2 -> 2 (OK) 5 -> 3 (CONFLICT) 3 -> 4 (OK) 6 -> 5 (OK)
A workaround: 8 -> 101 (OK) 2 -> 102 (OK) 5 -> 103 (OK) 3 -> 104 (OK) 6 -> 105 (OK)
If you really want to start at 1, you can repeat it and go from 101 -> 1, 102 -> 2, etc. 101 -> 1 (OK) 102 -> 2 (OK) 103 -> 3 (OK) 104 -> 4 (OK) 105 -> 5 (OK)
Thanks again for the great tool.
TJ
Hi TJ,
Thanks for sharing this information.
Best,
What an amazing solution!!!
Thank you!!!
So incredibly clever, team! Saved my skin.
Having some trouble getting this to work…it looks from the video like maybe the form editor has changed? When I paste the snippet into console and then enter the parameters, I get the message “ReferenceError: form is not defined”
Hi Charles,
I just tested the snippet again, and it works as expected. Can you confirm if you’re running the code on the Form Editor page?
Best,
This is a great help!! Thx for posting this!
Not working for me neither :S
It says: VM4599:1 Uncaught ReferenceError: gwChangeFieldId is not defined at :1:1
Hi Javier,
I just tested this on my end with GF 2.5.1 and it works as expected. Please note that you will have to first copy, paste and run the snippet in the browser console, before calling the function with the ID parameters. In case you’re still having issues with it, you can pick up a Gravity Perks license and get in touch with us via our Support form, so we can dig into this further.
Best,
Just wanted to say thanks for this!
If the new field ID is larger than form.nextFieldId then you should also update form.nextFieldId to one greater than the new field ID, or else you might have problems when fields are later added to the form.
This is some fantastic. Thanks for this!
Wow. Cool. A huge time saver when creating bulk gravity forms. Helps a lot when you have to create similar forms many times over in different contexts Gravity forms plugin with gravity perks plugins is now a must have for any wordpress based software now. No other plugin comes even close. thanks.
Hey Arvind, Thank you so much for the kind words. We hope you continue to enjoy all our awesome snippets and perks. 😃
Thanks. This is helpful.
I had no idea you could use the browser’s console as a “terminal”
Hi there,
The video is not working.
Hello Crystal, Thank you for that informtion. I have updated the page so the video should be working correctly now. Have a great day! 😃
This does not maintain the conditional logic for the questions. Ie if you have it set to show/hide a question based on ID30, and you change that to field ID50, then the conditional logic will break.
It might be a better idea to build this into a perk so you can account for all these conditions and edge-cases.
Hi Avi, thanks for the feedback. We don’t have plans to make this into a more robust tool but we’ll continue to track customer demand for such a tool.
Brilliant, thank you very much for sharing
Happy to help, Nuno. ?
I am curious if there is a way to pass in an array with fields to be changed. This is what I tried.
I created a php file with the following code:
http://snippi.com/s/y79rwcp
I then opened the form editor, and opened the Firefox Console.
I then passed in an array of field ids to change (pasted this in the console):
http://snippi.com/s/pzpj4qk
I then pasted your function in the console.
Finally, I pasted the following function call in the console:
http://snippi.com/s/b4n1r6z
So far, not successful.
Just letting you know my solution worked. Kept trying but it had changed the ids already.
Glad to hear it, Andre. ?
Just FYI, the array works but you have to be careful because it doesn’t have the built in success/fail of the GW function. So this array could possibly end up deleting your fields. What happens is this, you change Field ID 30 and there’s already a #30 in your form, this function will now delete the original and duplicate it into the original 30, leaving you with two #30. I know I’m probably not explaining it right but just be careful of something like the following:
my items = [ [1,30], [30,17] ]; in this example you have two fields, one with ID1 and another with ID30. What you may be expecting is that you change ID1 into ID30 and ID30 into ID17 but since it processes in order you end up with two ID17 that are duplicates of one another and the original ID1 is deleted.
Hay
This sounds great, I’ve set up a massive amount of conditional pricing, I’ve realized I’ve set up a checkbox list that should have been radial! Can I delete the check boxes and create a radial field, make the choices identical in the same order and then set the field Id to the original number of the checkbox? Do you think it will work or will all my conditional pricing break? It’s taken ages to implement!
Thanks
Ben
Ho my god! I just duplicated the form and gave it a go! It worked! hours saved! Thank you!
Awesome! Glad it worked!
Thanks! This solution is still working great. Saved me a ton of hassle.
Glad to hear it, Dan. ?
Super handy and super helpful! Thank you1
Glad to help, Jason!
Do we need to change ID to another number or can we give it a custom name? I tried to watch the video, but it does not appear to be working. I’m trying to give field IDs a custom name. Any help appreciated.
The field ID can only be a number. Gravity Forms does not support non-numeric field IDs.
This is an excellent little snippet. Still can’t believe after all this time GF hasn’t given us the ability to provide custom ID and Name attributes.
Any chance you have a solution for changing the FORM ID rather than the field ID? Same annoyance. I’ll pay you ;)
Thank you David!
Hi Jason, easiest solution would be to log into the database and modify it there (gf_form, gf_form_meta, gf_form_view). We don’t have a snippet for this one. If you’re looking to hire someone to create a more polished solution, codeable.io is a great resource. ?
I can’t even begin to express how inconvenient it is not NOT be able to assign fields custom IDs.
Hi, When I paste the gwChangeFieldId( 4, 12 ) into the console and press enter I get this: Uncaught ReferenceError: gwChangeFieldId is not defined at :1:1 and after I save the form noting happens. Thanks, Ronen
Did you copy and paste the function definition into your console first?
I did now. Thanks, It works !
Hi, so I am not sure how to do this.. I paste the code in the console, but where do I have to change the field id? gwChangeFieldId(), Where is this exactly? I can see at the beginning: gwChangeFieldId = function( currentId, newId ) {
Do I need to replace the numbers in currentId and newId in all code?
Please help
Solved! Thank you works perfect
Just a note, if you are using the repeater plugin, you have to get your field out of the repeater before this will work.
Noted. Thanks for sharing, TJ.
Not sure if I’m doing something wrong or not but I added this to the console and it told me it worked but upon saving, nothing changed. I’m wondering if an update this year changed this from working.
Hm, hard to say, Jo. I confirmed that this is still working on my end. If you need help with this and would like hands-on support, pick up a copy of Gravity Perks which includes complimentary support for our snippets.
Nice! Was looking for an easy way to do this rather than create a field array to rgar from. Bing bang boom – 2 seconds, done!
That’s what we like to hear, Joe!
Works like a charm. Thanks :)
Glad to help. :)
Hi David,
I wanted to let you know that I used your code to add a feature to one of my plugins called Mighty Gravity Forms: https://wordpress.org/plugins/bluecube-mighty-gravity-forms/
I hope you are ok with this. If not, definitely let me know.
Regards
All good. Thanks for sharing. :)
Hi, if I put the snippet in console and then call the function then i get following error:
gwChangeFieldId( 60, 100 ); ReferenceError: form is not defined [Learn More]
What do I do wrong? Browser Firefox 49.0.1
Thanks for any help!
Only thing I can think is that in your console, you’re not working with the “top” level document. Here’s what that looks like in Chrome (screenshot).
I am getting an “Uncaught ReferenceError: gwChangeFieldID is not defined. I had posted last week, but don’t see my original post. You had wanted me to export my form and send it…..where can I send that to?
I’m thinking you might not have copied the full snippet on step #3.
Hi,
Thanks for this snippet. I’m running to a problem when changing an address field id. The id does get changed, however, it doesn’t let you open the field box to show the advanced settings.
Could you send me an export of the form you’re trying to change the Address field ID on?
Thanks David. Unfortunately, I’m unable to export the form because there is excessive customization. However, I was able to get it to work by changing the values manually.
The error message I was getting from the console log was: Uncaught TypeError: form.fields[i].inputs[j].id.replace is not a function(…)
When I created a brand new form, and tried to change to field id on an address field, the code worked perfectly. So, there might have been something wrong with my particular form.
The way I changed the values manually was basically following the format of the code:
– example to 2. Then Open the console and type in “console.log(form);” to get the form array values. 3. Find the Fields Objects. and find the field that I wanted to change and change the id. 3. Then go to the Inputs Objects under the same Field Object. And Change the ID of the Input values. The ID of the Input values where changed from 1.1, 1.2, 1.3, etc. to 4.1,4.2,4.3 etc.
Lastly, close the console and update the form. And It should work.
I appreciate you trying to help though. If I run to anymore trouble, I’ll keep in contact.
Thanks Again
Awesome! Glad you were able to find a solution. Thanks for sharing. :)
Hi there,
This works, but do you know of a way to reset all the fields of a form? Basically to start over? Any new field I add is setting the ID’s in the 77000’s which is causing problems on the back end entries and output to pdf.
Yes, question: it says “Copy and paste this snippet into the console.” but there’s not snippet that I can find.
Hi Rod, at the top of the article is a “show snippet” button (it’s purple). If you click that, it will reveal the snippet).