Embedded forms
Processes can be started by anonymous users. Examples are a support ticket or an RMA return. The start step of such a process is still a form, but typically embedded in an external website.
Example: support ticket
Section titled “Example: support ticket”Let’s create a process where visitors can submit a support ticket, which will be resolved by support:
- A visitor submits their email address and a description of the issue without signing in.
- A member of the Support role opens the ticket in the Dashboard, sees the submitted details, and checks Done before completing the task.
In src/support-ticket-form.ts, export the schemas for both forms:
import { BooleanField, EmailField, TextArea, TextField } from "@pf/form-schema"import { Schema } from "effect"
export const supportTicketForm = Schema.Struct({ email: EmailField({ label: "Your email address", required: true }), issue: TextArea({ label: "Describe the issue", required: true }),})
export const resolveTicketForm = Schema.Struct({ submittedEmail: TextField({ label: "Contact email", readOnly: true }), submittedIssue: TextArea({ label: "Reported issue", readOnly: true }), done: BooleanField({ label: "Done", default: false, required: true }),})In src/org.ts, add the process below your existing org
definition. The embed property identifies the form as available for
embedding. The externalParticipantEmailField setting tells Process
Focus which field identifies the visitor.
import { Form, Process, Role } from "@pf/process"import { resolveTicketForm, supportTicketForm } from "./support-ticket-form"
const support = new Role(org, "support", { name: "Support" })const supportTicket = new Process(org, "support-ticket", { name: "Support ticket", purpose: "Collect and resolve support requests from the website",})
const submitTicket = new Form(supportTicket, "submit-ticket", { name: "Submit a support ticket", role: support, form: supportTicketForm, browser: { entrypoint: "src/support-ticket-form.ts", exportName: "supportTicketForm", }, embed: { externalParticipantEmailField: "email", sites: ["https://www.example.com"], thankYou: "Thanks. Your support request has been submitted.", },})
const afterSubmission = supportTicket.start(submitTicket)const resolveTicket = new Form(afterSubmission, "resolve-ticket", { name: "Resolve support ticket", role: support, form: resolveTicketForm, browser: { entrypoint: "src/support-ticket-form.ts", exportName: "resolveTicketForm", }, bindings: (state) => ({ submittedEmail: { default: state.email }, submittedIssue: { default: state.issue }, }),})
afterSubmission.next(resolveTicket).end()As the support role is specified on submitTicket support can also
start the submit-ticket process themselves.
The embed property controls how visitors use the start form:
externalParticipantEmailFieldnames the form field Process Focus uses to identify the visitor as an external participant. Here, it uses the address entered inemail.siteslists the exact external origins allowed to embed the form. Onlyhttps://www.example.comis allowed to embed this form;https://example.comis a different origin and would need its own entry.thankYouis the plain-text message the visitor sees after a successful submission. Use a blank line between paragraphs. HTML is not supported.
Embed the form in a website
Section titled “Embed the form in a website”On a page whose origin is listed in embed.sites, add this <script> tag
where you want the form to appear. In this example, the page is on
https://www.example.com and the Process Focus Dashboard is at
https://app.example.com.
<script src="https://app.example.com/processfocus-embed.js?form=/support-ticket"></script>Replace https://app.example.com with your Dashboard origin. Set form to the
full process path, including the leading / and any parent segments. Process
Focus uses /support-ticket to find the process’s embedded start form.
The script inserts an iframe where you placed the tag and resizes it to fit the form.
Security and submissions
Section titled “Security and submissions”Set Form.embed.sites to the exact origins of the external websites that may
embed the form. Browsers block unlisted external sites from framing it.
Process Focus also checks the request origin on submissions and form lookups.
An embedded form gives visitors access to a specific start step without giving them a Dashboard session. In the support ticket example, visitors can submit a ticket, and the follow-up task stays with the Support role.
The email address is supplied by the visitor and does not prove they own it. Origin checks restrict requests from unapproved websites in browsers. Automated clients can supply their own request headers, so these checks do not provide bot protection. Add separate anti-abuse controls if unwanted submissions would create significant work or trigger costly actions.
Limitations
Section titled “Limitations”- Only the start form can be embedded. The process must have exactly one start step. It can have follow-up steps, such as the Support task above.
- The form schema must run in the browser. Set
browser.entrypointandbrowser.exportNameto point to the shared schema used by the form. Keep server-only imports, such as database clients, out of that module. - Visitors cannot upload files through the embedded form. Leave upload fields out of the start form.