Client-side custom forms
Register a form with registerForm so the agent can show it in the chat, and handle the submitted values with your own code in the browser.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
A client-side form is a form you describe in JavaScript and register under a name. The agent shows it inside the chat when a conversation needs structured input, and your code receives the values when the visitor submits. Use it when you need your own validation or want to send the data straight to your own system.
If you only need to collect fields and keep them with the conversation, the Collect data action is simpler. See Collect data.
Register a form
window.askocto.registerForm("return_request", {
title: "Start a return",
description: "Tell us which order and why.",
submitLabel: "Send request",
fields: [
{ name: "orderNumber", label: "Order number", type: "text", required: true },
{ name: "email", label: "Email", type: "email", required: true },
{
name: "reason",
label: "Reason",
type: "select",
options: ["Too small", "Too large", "Damaged", "Other"],
},
{ name: "details", label: "Details", type: "textarea" },
],
onSubmit: async (values) => {
const res = await fetch("/api/returns", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(values),
})
if (!res.ok) throw new Error("We could not save your request.")
return { requested: true }
},
})
Configuration
| Key | Description |
|---|---|
title |
Heading shown above the form. |
description |
Optional short line under the heading. |
submitLabel |
Text of the submit button. |
fields |
List of field objects, described below. |
onSubmit(values) |
Called with an object of values keyed by field name. May be asynchronous. |
Field types
| Type | Notes |
|---|---|
text, email, tel, number |
Single-line inputs with matching validation. |
textarea |
Multi-line input. |
select |
Uses options, a list of strings. |
checkbox |
Gives true or false. |
date |
Gives an ISO date string. |
Each field takes name, label and optionally required. The form blocks submission until required fields are filled.
Show the form from the agent
Mention the form by name in a procedure step, for example: "If the order is eligible, show the return_request form." The agent then displays it at that point.
- Register the form in your page, after the embed script.
- Open Build > Procedures and add the step that names the form.
- Test on a page that loads your script.
You should see the form appear in the chat. After the visitor submits, the value you return from onSubmit goes to the agent, which can confirm the result in its next message. If onSubmit throws, the form shows the error message and stays open.
Tip: Return only what the agent needs to confirm the outcome, such as a status and a reference number.
Related pages
- Client-side custom actions runs code without showing a form.
- Procedures explains how steps reference forms and actions.
- Website integration overview lists every embed option.