BDMG UI

TrustedForm (Cert URL)

TrustedForm integration for landing pages: load the TrustedForm script, render hidden inputs for the certificate URL and token, and optionally get the cert URL or full certificate data in code via callbacks or useTrustedForm.

Installation

tsx
import { TrustedForm, useTrustedForm } from "@workspace/lp-core"

TrustedForm component

Render TrustedForm inside your form. It injects the TrustedForm script (if not already present) and two hidden inputs: xxTrustedFormCertUrl and xxTrustedFormToken. Use onCertUrlReady or onCertificateReady to get the cert URL (and token) when ready.

tsx
<form onSubmit={handleSubmit}>
  <TrustedForm onCertUrlReady={(url) => setCertUrl(url)} />
  <input name="email" />
  <button type="submit">Submit</button>
</form>

Get cert URL via callback

tsx
const [certUrl, setCertUrl] = useState("")

<TrustedForm onCertUrlReady={setCertUrl} />
// certUrl is set when the TrustedForm script populates the hidden field

Cert URL (when ready):

Waiting for TrustedForm script...

useTrustedForm hook

useTrustedForm(timeout?) returns getCertificateData, which resolves with { certUrl, token }. The hook polls the hidden fields until they have values or the timeout (default 2000ms) is reached. You must still render TrustedForm so the script and inputs exist.

tsx
const { getCertificateData } = useTrustedForm(2000)

const handleClick = async () => {
  const { certUrl, token } = await getCertificateData()
  console.log(certUrl, token)
}

TrustedForm component props

PropTypeDefaultDescription
onCertificateReady(certUrl: string, token: string) => void-Called when both cert URL and token are available.
onCertUrlReady(certUrl: string) => void-Called when the certificate URL is available (cert only).
enableSandboxbooleanfalseEnable TrustedForm sandbox mode.
provideReferrerbooleanfalsePass referrer to TrustedForm.
timeoutnumber2000Timeout (ms) for callback polling.

Hidden field names

The component renders hidden inputs with name="xxTrustedFormCertUrl" and name="xxTrustedFormToken" so they are included in form submissions. IDs are xxTrustedFormCertUrl_0 and xxTrustedFormToken_0.