You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/submitting-forms.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -317,3 +317,52 @@ mutation submit {
317
317
}
318
318
}
319
319
```
320
+
321
+
## Submitting Multi-page Forms
322
+
323
+
When submitting a multi-page form, you can use the `sourcePage` and `targetPage` inputs to validate a specific page of the form before proceeding to the next page. This can then be combined with the Mutation payload's `targetPageNumber` and `targetPageFormFields` to serve the correct fields for the next _valid_ page.
324
+
325
+
When using a `sourcePage`, only the fields on that page will be validated. If that page fails validation, the `targetPageNumber` and `targetPageFormFields` will return the current page number and fields, instead of the provided `targetPage` input. Similarly, if the page passes validation, but the `targetPage` is not available (e.g. due to conditional page logic), the `targetPageNumber` and `targetPageFormFields` will return the next available page number and fields.
326
+
327
+
Only once the `targetPage` input is greater than the number of pages in the form, will the submission be processed, _all_ the values validated, and the entry created. As such, when using this pattern, it is recommended to submit all the user-provided `fieldValues` inputs to the mutation, and not just the fields on the current page.
328
+
329
+
### Example Mutation
330
+
331
+
```graphql
332
+
mutation submit {
333
+
submitGfForm(
334
+
input: {
335
+
id: 50
336
+
fieldValues: [
337
+
# other form fields would go here.
338
+
{
339
+
# Text field value
340
+
id: 1
341
+
value: "This is a text field value."
342
+
}
343
+
]
344
+
saveAsDraft: false
345
+
sourcePage: 1 # The page we are validating
346
+
targetPage: 2 # The page we want to navigate to.
347
+
}
348
+
) {
349
+
errors {
350
+
id
351
+
message
352
+
}
353
+
confirmation {
354
+
message
355
+
}
356
+
entry { # Will only be returned if the `targetPage` is greater than the number of pages in the form.
357
+
databaseId
358
+
}
359
+
targetPageNumber # The page number to navigate to. Will be the same as the `sourcePage` if validation fails, and different than the `targetPage` if the `targetPage` is not available.
360
+
targetPageFormFields { # The form fields for the next page.
'description' => __( 'Draft resume URL. Null if submitting an entry. If the "Referer" header is not included in the request, this will be an empty string.', 'wp-graphql-gravity-forms' ),
127
127
],
128
+
'targetPageNumber' => [
129
+
'type' => 'Int',
130
+
'description' => __( 'The page number of the form that should be displayed after submission. This will be different than the `targetPage` provided to the mutation if a field on a previous field failed validation.', 'wp-graphql-gravity-forms' ),
131
+
],
128
132
];
129
133
}
130
134
@@ -161,14 +165,15 @@ public static function mutate_and_get_payload(): callable {
0 commit comments