Skip to content

Commit 3061d5c

Browse files
committed
Enhance form configuration to support project ID
1 parent d52a635 commit 3061d5c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/formspree-ajax/src/form.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
createClient,
23
getDefaultClient,
34
isSubmissionError,
45
appendExtraData,
@@ -421,7 +422,9 @@ export const initForm = <T extends FieldValues = FieldValues>(
421422
const form = getFormElement(config.formElement);
422423
const formKey = config.formId;
423424
const endpoint = config.origin ?? DEFAULT_ENDPOINT;
424-
const client: Client = getDefaultClient();
425+
const client: Client = config.projectId
426+
? createClient({ project: config.projectId })
427+
: getDefaultClient();
425428

426429
const context: FormContext<T> = {
427430
form,

packages/formspree-ajax/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ export type MessageType = 'success' | 'error';
116116
* @template T - The type of field values for the form, defaults to FieldValues.
117117
*/
118118
export interface FormConfig<T extends FieldValues = FieldValues> {
119-
// TODO: add a project id
119+
/**
120+
* The Formspree project ID. When provided, submissions are sent to
121+
* `/p/{projectId}/f/{formId}` instead of `/f/{formId}`.
122+
*/
123+
projectId?: string;
120124

121125
/**
122126
* The form element to attach to, either as an HTMLFormElement or a CSS selector string.

0 commit comments

Comments
 (0)