This document explains the role of form.html and the associated JavaScript files in this repository at a high level. It orients contributors to where behavior lives and how to run and edit the form locally.
Run the project locally and open the form page:
python3 -m http.server 8080
# open http://localhost:8080/form.html
form.html — The form used to capture leads.js/form.js — Form-specific logic: validation, submission handling, event wiring, and any client-side capture logic.js/site.js — Site-wide JavaScript utilities and behaviors used across pages (non-form-specific helpers).css/ — Styling for the form variants; see the CSS files for visual customization.Documentation/ — Deeper guides and references (validation rules, API details, customization notes).form.html provides the markup and data attributes that drive client-side behavior.js/form.js attaches event listeners to inputs and the submit button, performs client-side validation, and prepares payloads for submission (or triggers analytics/capture hooks).js/site.js provides common helpers (DOM utilities, polyfills, or global event handlers) used by form.js.css/ keeps presentational changes separate from behavior, allowing easy layout/theme tweaks.js/site.js captures attribution data (mtm_*, UTM values, campaign hints, language, entry/referrer URLs) and stores a normalized record in localStorage.js/form.js.js/form.js reads attribution and browser context, then enriches fields (IP, country, language, campaign/UTM, website-derived metadata).localStorage with record expiry.js/form.js limited to the form lifecycle (validation, UX, payload creation). Offload shared utilities to js/site.js.Documentation/ folder first.https://api4.ipify.org and https://api6.ipify.org for public IP lookup.https://free.freeipapi.com for IP metadata (for example country/city).https://api.microlink.io for website metadata enrichment.i18next for UI translations when available (fallback translations remain in js/form.js).d365mktforms APIs for Dynamics lookup interactions when available.js/form.js.d365mkt-afterformload).mtm_*, utm_*, crm_campaign) on entry page.localStorage values.ipify, freeipapi, and microlink for CORS, blocking, or timeout errors.window.d365mktforms is available and lookup field logical names are correct.This project exposes two primary frontend scripts. The descriptions below summarize the main functions and responsibilities so contributors can find and modify behavior quickly.
js/form.js (js/form.js) — form-focused automation and UX helpers:
logInfo, logWarn, logError, logDebug, updateDebugState — consistent console output and debug state persistence.APP_CONFIG.selectors and getFieldFromSchema — central place to resolve form fields by name, id, or title.populateMTMFields, bindSubmissionUrlCapture, runPopulateOnce — read attribution (mtm_*) and fill matching form fields, with retries and submit-time capture.getPreferredBrowserLanguage, getLcidForLanguageTag, initializeUiTranslations, applyUiFieldTranslations, setUiLanguage — detect browser language and apply label translations (with i18next fallback).getFieldByLabelText, getEmailField, getWebsiteFieldInput — robust lookup across document and same-origin iframes.extractDomainFromEmail, getWebsiteFromDomain, syncWebsiteFromEmail, plus binding helpers to attach listeners.fetchAndPopulateWebsiteInfo, formatWebsiteInfo, bindWebsiteMetadataListeners — fetch page metadata (via Microlink) and write to form fields.getClientIP, fetchSafe, formatIpData, startIpScript, runOnce — orchestrates IP detection, metadata fetch, and writes to the IP field and related country/language fields.normalizeText, queryFirst, dispatchChangeEvents, setIpFieldWithRetry — small helpers used throughout.js/site.js (js/site.js) — site-level attribution capture and storage:
capture, readStoredRecord, writeRecord, clearStoredRecord — build and persist a canonical attribution record into localStorage.normalizeParamMap, serializeParamMap, getFirstParamValue — helpers for parsing URL search params and serializing UTMs/MTM keys.hasAnyAttribution, shouldReset, mergeMissingMtmFields, mergeMissingMetaFields — rules for merging or resetting stored attribution data.window.SiteAttribution with capture, get, and helpers — consumer-facing interface used by js/form.js and page templates.Together these scripts separate concerns: js/site.js focuses on capturing and persisting cross-page attribution, while js/form.js consumes that data to enrich forms (autofill, UX, metadata, and diagnostics).
Generated on 2026-04-08 — concise README for form.html and its JS files.