Tip
A version of the review page – called the "Preview page" – can be displayed by appending ?page=0 to the url.
You can choose between two types of spam prevention. Cloudflare Turnstile or a simple "honeypot".
- You can configure the
turnstileSiteKeyandturnstileSecretKeyin the site configuration, or in the no.item.forms.cfg file under XP_HOME/config.# These testing keys will always succeed turnstileSiteKey=1x00000000000000000000BB turnstileSecretKey=1x0000000000000000000000000000000AA
- The
[name]of the honeypot field in the HTML can be configured under the site configuration. The default value is"website".
Tip
See the Turnstile documentation page for more test keys.
You can enable and configure the built-in "Email" form type under the site config. If you enable it, the following fields must be configured in the site config for the xp-forms app:
| Field | Description |
|---|---|
| Sender email address | The "from" address used when sending form submission emails. Must be a whitelisted address on your mail server. |
| Receiver email address | The address form submissions are sent to. |
Important
Both fields are required for email submissions to work. If either is missing, the form submission will fail with an error.
You can add an event listener to your applications main.ts file to handle form submissions.
import { listener } from "/lib/xp/event";
type CustomFormSubmitEvent = {
data: {
formId: string;
values: Record<string, string | string[]>;
};
};
listener<CustomFormSubmitEvent>({
type: "custom.form.submit",
callback: (event) => {
// send email or do something else with `event.data.values`
},
localOnly: true,
});By registering a JSON-schema that you expect the form to conform to you can help the editor remember which fields are necessary to include in the form.
In your application create a file forms/forms.ts that exports the extensions function.
const EMAIL_FORM_RESULT_SCHEMA = {
$schema: "https://json-schema.org/draft/2020-12/schema",
title: "Contact email",
type: "object",
properties: {
name: {
type: "string",
description: "Name",
minLength: 3,
},
email: {
type: "string",
description: "Email",
},
subject: {
type: "string",
description: "Subject",
},
},
required: ["name", "email", "subject"],
};
export function extensions(req) {
return {
id: "email",
displayName: "My API-backed form type",
description: "This is a form where the data will be sent to an API, and it needs a specific shape.",
jsonSchema: EMAIL_FORM_RESULT_SCHEMA,
values: () => {
// You can use the http-client to fetch data from an API here and return it to be used in the form
return {
email: "this.is@my.email"
};
}
};
}