Skip to content

[6.x] Forms 2: Expose form sections, pages and access restrictions in the REST & GraphQL APIs - #15349

Open
duncanmcclean wants to merge 2 commits into
forms-2from
api-form-sections-pages
Open

[6.x] Forms 2: Expose form sections, pages and access restrictions in the REST & GraphQL APIs#15349
duncanmcclean wants to merge 2 commits into
forms-2from
api-form-sections-pages

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request implements support for form sections in the REST API, and pages in both the REST and GraphQL APIs. The GraphQL API has had sections since #11466 but the REST API never got them, and neither API exposed pages.

sections returns every section across all pages, so it's the easy way to render a single-page form with the same structure as the Control Panel. pages returns each page's id, display, instructions and its sections, for rendering multi-page forms. Single-page forms return a single page.

This PR also fixes the GraphQL sections field only returning the first page's sections on multi-page forms.

Access restrictions

This PR also exposes require_login and restriction_message alongside the existing status, so headless frontends can tell whether a form is currently accepting submissions and what to show when it isn't.

restriction_message only covers the closed and limit reached cases. The login case is deliberately left out, since the API can't know who is visiting a headless frontend. require_login is exposed as a plain boolean instead so the frontend can make that call itself.

REST API

GET /api/forms/contact

{
  "data": {
    "handle": "contact",
    "title": "Contact",
    "fields": { "name": {...}, "email": {...} },
    "sections": [
      { "display": "Your Details", "instructions": null, "fields": { "name": {...}, "email": {...} } }
    ],
    "pages": [
      { "id": "main", "display": "Page 1 of 1", "instructions": null, "sections": [...] }
    ],
    "status": "open",
    "require_login": false,
    "restriction_message": null,
    "api_url": "http://example.com/api/forms/contact"
  }
}

GraphQL

{
    form(handle: "contact") {
        status
        require_login
        restriction_message
        pages {
            id
            display
            instructions
            sections {
                display
                instructions
                fields { handle display }
            }
        }
    }
}

Closes statamic/ideas#1320

duncanmcclean and others added 2 commits September 2, 2026 14:46
… graphql apis

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qe1g6yd25kh7oTxtWfzB95
Sign up for free to 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