Commit ca5d0f2
Forms: add form preview functionality (#46935)
* Forms: add form preview functionality
Add preview functionality to Jetpack Forms allowing admins/editors to
preview forms at a temporary nonce-based URL. Forms render within the
site's page template with submissions disabled in preview mode.
- Add Form_Preview class to handle preview rendering
- Add REST endpoint for generating preview URLs
- Add preview action to forms dashboard list
- Add preview menu item to form editor
- Block form submissions in preview mode (PHP and JS)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Update projects/packages/forms/src/contact-form/class-form-preview.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Forms: fix form preview rendering
- Use the form's ID for the fake post context instead of 0, which was
causing the form ID validation to fail (since '0' is falsy in PHP)
- Add preview mode exceptions to the module and frontend checks in
gutenblock_render_form() so forms render during preview
- Add jetpack_is_frontend filter to ensure proper frontend detection
- Set is_404 and is_feed to false in the query context
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Forms: add tests for Form_Preview class
Add comprehensive unit tests for the Form_Preview functionality:
- Test hook registration via init()
- Test query variable registration
- Test preview mode state management
- Test preview URL generation for various scenarios
- Test access verification (logged out, no capability, invalid nonce, valid)
- Test jetpack_is_frontend filter behavior
- Test handling of draft forms
* Forms: use registerPlugin for preview menu item
Switch from registerJetpackPlugin to WordPress core's registerPlugin
for the form preview menu item. This ensures the plugin renders
correctly in the form editor context.
Also adds loading state to show "Opening preview…" feedback while
the preview URL is being fetched.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Use autosave for form preview
Ensure previews reflect the latest unsaved edits by using the editor autosave. In PHP, Form_Preview now checks wp_get_post_autosave and uses the autosave post if it's newer than the saved form. In the editor plugin, the preview button reads editor dirty/autosaveable state and calls the core/editor autosave before requesting the preview URL; the button text and hook deps were updated accordingly. Files changed: class-form-preview.php, preview-button.tsx.
* Forms: add preview action to wp-build dashboard
Add the "Preview" action to the Forms list in the wp-build dashboard
(routes/forms/stage.tsx), matching the functionality already present
in the React Router dashboard.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Addressing issue. Improve form preview UX and error handling
Clarify changelog and refine preview behavior and UI. Stop returning a WP_Error in preview submission handler (now returns early) and surface the preview-mode message to client-side strings. Make preview CSS enqueuing robust by using filemtime when available with a fallback version, and update CSS to use margin-block-end. In the dashboard and editor preview code, add notices integration to show a snackbar error when preview URL generation fails and include the notice dispatcher in hook deps.
* Improve Form_Preview null-safety and versioning
Use a boolean true for current_time GMT flag, add nullable WP_Post typing and an early return to render_form_preview_content to avoid errors when no form is provided, and switch CSS versioning to the package PACKAGE_VERSION constant for accurate asset versioning.
* Remove redundant setAccessible calls in test
Remove ReflectionProperty::setAccessible(true) calls from Form_Preview_Test methods. These calls were unnecessary for setting the static property and can cause issues with newer PHP versions where setAccessible is deprecated, so the tests are simplified and made more compatible.
* Refactor Form_Preview tests and assertions
Clean up and simplify Form_Preview unit tests: rename variables (editor/subscriber IDs), create users with randomized logins/emails, and streamline post type registration and test form content. Remove reflection-based preview-mode helpers and consolidate setup/teardown to rely on BaseTestCase. Update and rename tests to focus on generate_preview_url, verify_preview_access, maybe_render_preview, and draft preview behavior, adjusting assertions accordingly and removing the data provider import and related invalid-ID test matrix.
* simplify the error.
* minor text copy
* fix ternary on i18n message
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Douglas <douglas.henri@automattic.com>
Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/21693256612
Upstream-Ref: Automattic/jetpack@54dcce31 parent 7c278a7 commit ca5d0f2
24 files changed
Lines changed: 637 additions & 22 deletions
File tree
- build/routes/forms
- dist
- contact-form/css
- dashboard
- form-editor
- modules/form
- routes/forms
- src
- blocks/contact-form
- contact-form
- css
- dashboard/forms
- form-editor
- plugins
- modules/form
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
59 | 66 | | |
60 | 67 | | |
61 | 68 | | |
| |||
1565 | 1572 | | |
1566 | 1573 | | |
1567 | 1574 | | |
1568 | | - | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | 1575 | | |
1576 | 1576 | | |
1577 | 1577 | | |
| |||
3717 | 3717 | | |
3718 | 3718 | | |
3719 | 3719 | | |
| 3720 | + | |
3720 | 3721 | | |
3721 | 3722 | | |
3722 | 3723 | | |
| |||
27017 | 27018 | | |
27018 | 27019 | | |
27019 | 27020 | | |
| 27021 | + | |
| 27022 | + | |
| 27023 | + | |
| 27024 | + | |
| 27025 | + | |
| 27026 | + | |
| 27027 | + | |
| 27028 | + | |
| 27029 | + | |
| 27030 | + | |
| 27031 | + | |
| 27032 | + | |
| 27033 | + | |
| 27034 | + | |
| 27035 | + | |
| 27036 | + | |
| 27037 | + | |
| 27038 | + | |
| 27039 | + | |
| 27040 | + | |
27020 | 27041 | | |
27021 | 27042 | | |
27022 | 27043 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments