Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Hidden form field value overwritten by a script: how to fix it

CNV-009Medium impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

Hidden fields are form inputs visitors never see, such as <input type="hidden" name="lead_source">. They carry data like UTM parameters, the Google click ID (gclid), the landing page or a campaign name into your CRM.

The problem appears when two scripts both write to the same field. Your script fills it correctly, then a later one (a form plugin, a page builder, a tracking tag, a cache or a theme script) sets it back to empty or to a default. The last write wins, and that is what gets submitted.

This differs from a field that is never populated at all (see CNV-008). Here the value is set, then lost.

Why it costs you leads or sales

The lead is not lost, but its source is. Sales sees a contact with no campaign, no keyword and no click ID. You cannot tell which ads produce real leads, offline conversion uploads to Google Ads fail without a gclid, and routing rules based on a hidden value (region, service, owner) send leads to the wrong place or nowhere.

Because the form still submits, nobody gets an error. The damage shows up weeks later as a report full of Direct or Unknown.

Where the value is lost
  1. Visitor landsURL has utm and gclid
  2. Your script fills fieldValue is correct
  3. Later script resets itField becomes blank or default
  4. Form submittedBlank value sent
  5. CRM recordNo source or click ID

The field is filled correctly, then overwritten before submit.

A field arrives empty

The form submits, but one value is missing from what the CRM receives.

How to check if your site has it

Check a hidden field by hand
  1. Open the page with test parameters

    Visit your form page with a URL such as ?utm_source=test&utm_campaign=hidden-check&gclid=TEST123.

  2. Inspect the hidden field

    Right-click the form, choose Inspect, and find the hidden input in the Elements panel. Note its value right after load.

  3. Watch it change

    Wait a few seconds, click into the form, and look again. Changed values flash in the panel. If the value goes blank, something overwrote it.

  4. Find the writer

    Right-click the input in Elements, choose Break on, then Attribute modifications. Reload and the debugger stops on the script that changes it.

  5. Compare with the CRM

    Submit a test lead and open the record. If the field is empty there but filled on the page, the overwrite happens at or before submit.

How to fix it

The fix is always the same idea: make sure only one thing owns the field, and that it writes after any reset. The exact place depends on your platform.

Fix by platform
  1. Use the plugin's own dynamic value

    In forms like Gravity Forms, Contact Form 7 add-ons or Fluent Forms, set the hidden field's default to a dynamic parameter (for example the field's Allow field to be populated dynamically option) instead of a custom script.

  2. Disable duplicate scripts

    If a UTM plugin and a theme snippet both fill the field, remove one. Test by deactivating plugins one at a time on a staging copy.

  3. Exclude the page from caching

    If your cache plugin serves a stale form, exclude the landing page or exclude query strings from cache rules.

Set hidden fields at load and again on submitjavascript
function getParam(name) {
  return new URLSearchParams(window.location.search).get(name) || '';
}

function fillHidden(form) {
  var map = {
    utm_source: getParam('utm_source'),
    utm_campaign: getParam('utm_campaign'),
    gclid: getParam('gclid')
  };
  Object.keys(map).forEach(function (key) {
    var input = form.querySelector('input[name="' + key + '"]');
    if (input && map[key]) { input.value = map[key]; }
  });
}

document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('form').forEach(function (form) {
    fillHidden(form);
    // Capture phase: runs before most other submit handlers.
    form.addEventListener('submit', function () { fillHidden(form); }, true);
  });
});
Hidden field behaviour

Before

  • Two scripts write to the same field
  • Value is reset after load
  • CRM shows blank source and gclid

After

  • One script owns the field
  • Value is set again just before submit
  • CRM record carries the right source and gclid

How to confirm it's fixed

Verify end to end
  1. Repeat the test URL

    Open the form page with ?utm_source=test&utm_campaign=hidden-check&gclid=TEST123 in a fresh private window.

  2. Submit a test lead

    Fill the form with a clearly labelled test contact and submit it.

  3. Check the payload

    Open the CRM record or the webhook log and confirm utm_source, utm_campaign and gclid hold your test values.

  4. Test other paths

    Repeat on mobile, in a popup version of the form and after a multi-step form advances, as those often rebuild the fields.

How to prevent it happening again

Prevention checklist
  • Give each hidden field exactly one owner (plugin, tag or script).
  • Document which field names your CRM expects and which script fills each.
  • Retest a lead with UTM parameters after every plugin, theme or tag update.
  • Retest after adding a new popup, chat widget or form step.
  • Keep cache rules from serving stale forms on landing pages.
  • Set up an automated test that checks the CRM payload, not just that the form submits.
How it usually unfolds
  1. Day 1

    A plugin update adds its own script that resets form fields on load.

  2. Day 2

    Leads keep arriving, so nobody notices anything wrong.

  3. Week 3

    A report shows paid leads marked Unknown or Direct.

  4. Week 3

    The overwriting script is found and removed; the value is set again on submit.

How FunnelGuard handles this

FunnelGuard detects this issue today. A robot visitor opens your form page on a schedule, fills and submits the form as a test lead, and checks the payload sent to your CRM webhook. The check looks for the expected hidden field values in that payload (a payload_contains check). If a value you expect, such as a source or campaign, arrives blank or missing, the check fails.

A failure is re-checked from a second region before one alert goes out, by email, Slack, Teams, WhatsApp, webhook or PagerDuty, with a screenshot and a likely cause. Test traffic is marked with utm_source=funnelguard and fg_test=1, so you can filter it out of reports. It never bypasses CAPTCHAs or bot protection.

The Free plan covers 1 site and 2 journeys with daily checks and no card. Paid plans start at $39/month with a 3-day free trial, and a free read-only website audit is available.

Questions people ask

Why is my hidden field empty when the form is submitted?

Usually a second script sets the field after yours, or the form is rebuilt after your script ran. The last write wins, so a blank value is submitted. Inspect the field in your browser and use Break on attribute modifications to find the script.

Why does my gclid hidden field show in the page but not in the CRM?

The value may be reset between page load and submit, or the CRM field mapping may not match the field name. Submit a test lead with a test gclid in the URL and compare the form payload with the CRM record to see where it disappears.

How do I find which script overwrites a hidden input?

Open DevTools, find the input in the Elements panel, right-click it and choose Break on, then Attribute modifications. Reload the page and the debugger pauses on the code that changes the value.

How do I make sure my hidden field value is not overwritten?

Let one script own the field, and set the value again on the form's submit event using a capture-phase listener. That way a late reset cannot change what is sent.

Can caching cause hidden field values to be wrong?

Yes. A cached page can serve a stale form or old script state. Exclude landing pages with query strings from cache or fill the fields client-side so they do not depend on the cached HTML.

Can a form plugin reset hidden fields on its own?

Yes. Some form plugins and page builders re-render the form after load, for example when a popup opens or a multi-step form advances, and that can clear values set earlier. Fill the field after the re-render or on submit.

Can FunnelGuard detect a hidden field being overwritten?

Yes. It submits a test lead on a schedule and checks that the payload sent to your CRM webhook contains the values you expect. If a value is missing or blank, you get an alert with a screenshot and a likely cause.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: payload_contains on CRM webhook.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.