Home › Forums › Snippets & Custom Code › Gravity Forms API traps that cost us hours (and how to post code here)

Gravity Forms API traps that cost us hours (and how to post code here)

Four lessons from production code on our own sites. Each one cost us an afternoon.

  1. REST PUT replaces the whole object. PUT /gf/v2/entries/{id} with one field in the body wipes every other field on the entry. PUT /gf/v2/forms/{id} does the same to a form, notifications and confirmations included. Fetch the full object, change it, and send all of it back.
  2. For one field, use GFAPI::update_entry_field(). It changes a single value without touching the rest of the entry, and it doesn't fire feeds or notifications.
  3. Custom merge tags shaped like {label:123} get eaten. Gravity Forms treats any {anything:digits} as a field merge tag and substitutes it before gform_replace_merge_tags runs. Handle your tag in gform_pre_replace_merge_tags, or use a shape that doesn't collide, like {label|123}.
  4. gform_merge_tag_filter doesn't get the tag's label. Its second argument is the field or input ID, so checking it for a label string never matches.

Posting code here

  • Say where it runs: functions.php, a snippet plugin, or an mu-plugin, plus the hook and priority.
  • Include the Gravity Forms version you tested on.
  • Strip API keys, license keys, and URLs you don't want public.
  • Keep short snippets inline. Put anything longer in a GitHub Gist so the indentation survives.

Looking for something ready-made? Our snippet library is free, and every snippet links to its GitHub source.

<p>Four lessons from production code on our own sites. Each one cost us an afternoon.</p><ol><li><strong>REST <code>PUT</code> replaces the whole object.</strong> <code>PUT /gf/v2/entries/{id}</code> with one field in the body wipes every other field on the entry. <code>PUT /gf/v2/forms/{id}</code> does the same to a form, notifications and confirmations included. Fetch the full object, change it, and send all of it back.</li><li><strong>For one field, use <code>GFAPI::update_entry_field()</code>.</strong> It changes a single value without touching the rest of the entry, and it doesn't fire feeds or notifications.</li><li><strong>Custom merge tags shaped like <code>{label:123}</code> get eaten.</strong> Gravity Forms treats any <code>{anything:digits}</code> as a field merge tag and substitutes it before <code>gform_replace_merge_tags</code> runs. Handle your tag in <code>gform_pre_replace_merge_tags</code>, or use a shape that doesn't collide, like <code>{label|123}</code>.</li><li><strong><code>gform_merge_tag_filter</code> doesn't get the tag's label.</strong> Its second argument is the field or input ID, so checking it for a label string never matches.</li></ol><p><strong>Posting code here</strong></p><ul><li>Say where it runs: <code>functions.php</code>, a snippet plugin, or an mu-plugin, plus the hook and priority.</li><li>Include the Gravity Forms version you tested on.</li><li>Strip API keys, license keys, and URLs you don't want public.</li><li>Keep short snippets inline. Put anything longer in a GitHub Gist so the indentation survives.</li></ul><p>Looking for something ready-made? Our <a href="https://brightleafdigital.io/code/">snippet library</a> is free, and every snippet links to its GitHub source.</p>

Leave a Reply

This topic is locked. No more replies are allowed.

Log in or create an account to reply.