How to Fix A Corrupted Gravity Forms Field Using a SQL backup

Recently we had an instance where a Gravity Form containing some custom JS became corrupted, with half of the code missing.  I was able to restore the original Javascript from a SQL backup doing the following:

  1. Download a SQL backup (in my case I use Updraft) with a known “good” Gravity form
  2. Open the extracted backup (I’m using VS code)
  3. Search for your form’s title, in my case it’s “Ram Food Recovery Event Registration”
  4. Then I found something that looks like this:

    (17, ‘{“title”:”Ram Food Recovery Event Registration”,”description”:  …  ,”enableAttachments”:false}}’),

  5. Luckily for us Gravity Forms saves custom code in plaintext, but we’ll have to finesse it a bit.
  6. First remove the newlines and tabs ( \\n and \\t)
  7. Next replace \\” with “
  8. Next replace \\/ with /
  9. Finally you should have some functional Javascript code.  In my case I also pasted the code within an online JS beautifier tool to properly ident/format it for easier reading