Skip to content

[6.x] Forms 2: Provide pages array to {{ form:create }} tag - #14867

Closed
duncanmcclean wants to merge 3 commits into
forms-2from
forms-2-tag-data
Closed

[6.x] Forms 2: Provide pages array to {{ form:create }} tag#14867
duncanmcclean wants to merge 3 commits into
forms-2from
forms-2-tag-data

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request provides a pages array to the {{ form:create }} tag, allowing developers to loop through a form's pages on the frontend.

Forms always have at least one page internally. To add more pages, you'll need to install the first-party Forms Pro addon.

Usage

{{ form:contact }}
{{ pages }}
<h2>{{ display }}</h2>
{{ sections }}
<h3>{{ display }}</h3>
{{ form:fields }}
{{ field }}
{{ /form:fields }}
{{ /sections }}
<button>{{ button_label }}</button>
{{ ifnotfirst }}
<buttontype="button">{{ previous_page_label }}</button>
{{ /if }}
{{ /pages }}
{{ /form:contact }}

The following variables can be used when looping through pages:

VariableDescription
idThe page's handle.
displayThe page's label.
instructionsThe page's help text, if any.
button_labelDefaults to Next for every page but the last, and Submit for the last page.
previous_page_labelThe "previous page" button label. Absent on the first page.
sectionsThe page's sections, with nested fields. The same variables are available as in the normal {{ sections }} loop.

JS Drivers can provide additional data (eg. an Alpine expression) by implementing addToRenderablePageData():

publicfunctionaddToRenderablePageData($page, $data)
{
return [
'show_page' => "...",
];
}

This mirrors the existing addToRenderableFieldData() hook. To avoid introducing breaking changes, this method is currently commented out in the JsDriver interface and can be un-commented in v7.

@duncanmcclean

Copy link
Copy Markdown
MemberAuthor

I've merged this into #14840

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@duncanmcclean