Service for retrieving form schemas and submitting form data.

Accessible via lynkow.forms. Forms are dynamic, CMS-managed forms with configurable fields, validation rules, and spam protection. The service automatically handles honeypot anti-spam fields on submissions. Form schemas are cached for 10 minutes (MEDIUM TTL).

Access via: lynkow.forms

Methods

3 methods

clearCache

TypeScript
clearCache(): void

Invalidates all cached form schema responses. Call this if you know a form definition has changed and want to fetch the latest schema.

Returns: void


getBySlug

TypeScript
getBySlug(slug: string): Promise<Form>

Retrieves a form definition by its slug, including the field schema, validation rules, settings (submit label, success message), and spam protection configuration (honeypot/reCAPTCHA). Cached for 10 minutes.

Parameter

Type

Description

slug

string

The unique slug of the form (e.g. 'contact', 'newsletter', 'feedback')

Returns: Promise<Form>

TypeScript
const form = await lynkow.forms.getBySlug('contact')
// Iterate fields to render the form dynamically
form.schema.forEach(field => {
  console.log(field.name, field.type, field.required)
})
// Check spam protection config
if (form.recaptchaEnabled) {
  // Render reCAPTCHA widget using form.recaptchaSiteKey
}

submit

TypeScript
submit(slug: string, data: FormSubmitData, options?: SubmitOptions & BaseRequestOptions): Promise<FormSubmitResponse>

Submits form data to the API. Anti-spam honeypot fields (_hp, _ts) are injected automatically by the SDK -- you do not need to add them yourself. If the form has reCAPTCHA enabled, pass the token via options.recaptchaToken.

Parameter

Type

Description

slug

string

The slug of the form to submit to (e.g. 'contact')

data

FormSubmitData

Key-value pairs matching the form's field names.<br> Values can be string, number, boolean, or File.

options

SubmitOptions & BaseRequestOptions

Optional submission options:<br> - recaptchaToken — the reCAPTCHA v3 token (required if reCAPTCHA is enabled on the form)<br> - fetchOptions — custom fetch options (e.g. AbortSignal)

Returns: Promise<FormSubmitResponse>

TypeScript
const result = await lynkow.forms.submit('contact', {
  name: 'John Doe',
  email: '[email protected]',
  message: 'Hello!'
})

if (result.status === 'pending') {
  // Show "check your email" confirmation
} else {
  // Show success message
  console.log(result.message)
}