sendFormSubmission
sendFormSubmission sends form data from a form brick to a React Bricks form configured in the dashboard.
Use it when your project uses Form Management and you need a frontend form to trigger the configured form actions.
Signature
Section titled “Signature”const sendFormSubmission = async ({ appId, appEnv, token, formId, emailAddress, data, fetchOptions,}: SendFormSubmissionParams): Promise<SendFormSubmissionResult>Parameters
Section titled “Parameters”interface SendFormSubmissionParams { appId: string appEnv: string token: string formId: string emailAddress: string data: Record<string, any> fetchOptions: types.FetchOptions}| Parameter | Definition |
|---|---|
appId | The React Bricks app ID. |
appEnv | The React Bricks environment. |
token | The form submission token. |
formId | The ID of the form configured in React Bricks. |
emailAddress | The submitter email address. |
data | Object containing the submitted form values. |
fetchOptions | Fetch options for React Bricks API calls. For example, pass { apiPrefix: rbContext.apiPrefix }. |
Return value
Section titled “Return value”interface SendFormSubmissionResult { success: boolean statusCode: number message: string}| Property | Definition |
|---|---|
success | true when the form submission was accepted. |
statusCode | HTTP status code returned by the submission endpoint. |
message | Message describing the result of the form submission. |
Usage example
Section titled “Usage example”sendFormSubmission is typically called from a form brick submit handler. The brick should collect field values, call sendFormSubmission, and then show a success or error state to the visitor.
try { const result = await sendFormSubmission({ appId: rbContext.appId, appEnv: rbContext.environment, token, formId, emailAddress: email, data, fetchOptions: { apiPrefix: rbContext.apiPrefix }, })
if (result.success) { // Show a success state. } else { // Show result.message or a fallback error. }} catch (err) { // Handle network or unexpected errors.}Form actions
Section titled “Form actions”The function submits data to the form. The form configuration in the dashboard decides what happens next, such as:
- saving submitted data
- sending an email
- subscribing the visitor to an Email Sending Provider list
- calling a Zapier webhook