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
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.
<form onSubmit={handleSubmit}>
<TrustedForm onCertUrlReady={(url) => setCertUrl(url)} />
<input name="email" />
<button type="submit">Submit</button>
</form>Get cert URL via callback
const [certUrl, setCertUrl] = useState("")
<TrustedForm onCertUrlReady={setCertUrl} />
// certUrl is set when the TrustedForm script populates the hidden fieldCert 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.
const { getCertificateData } = useTrustedForm(2000)
const handleClick = async () => {
const { certUrl, token } = await getCertificateData()
console.log(certUrl, token)
}TrustedForm component props
| Prop | Type | Default | Description |
|---|---|---|---|
| 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). |
| enableSandbox | boolean | false | Enable TrustedForm sandbox mode. |
| provideReferrer | boolean | false | Pass referrer to TrustedForm. |
| timeout | number | 2000 | Timeout (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.