Skip to content

Forms: Display success info after form submission without reload #44204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

dhasilva
Copy link
Contributor

@dhasilva dhasilva commented Jul 4, 2025

Part of FORMS-69

Proposed changes:

  • Displays the submitted data without reload if the feature flag is on
  • Fixes forms on widgets and on paginated content (when the feature flag is on)
  • Does not deal with submission errors (network, mostly)
  • Does not deal with transitions

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Make sure the feature flag is disabled
  • Submit some forms. Test post forms, pages with more than one form, widgets...
  • Check that it works exactly the same as in trunk, with no regressions. Forms on widgets do not work on trunk, and forms on paginated posts (your Home, add some posts with forms in them) also do not work. This is expected, same as trunk.
  • Enable the flag with add_filter( 'jetpack_forms_enable_ajax_submission', '__return_true' );
  • Reload the pages and submit again. Test the same cases.
  • Check that the information is displayed without a reload on all cases
  • Check that you can go back and the form is displayed without a reload, in a reset state
  • Check that you can fill it and submit again
  • Check that emails are sent as expected
  • Check that the forms are displayed in the dashboard as expected

@dhasilva dhasilva requested a review from a team July 4, 2025 23:33
@dhasilva dhasilva self-assigned this Jul 4, 2025
@dhasilva dhasilva added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the update/forms-submit-ajax-json-frontend branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/forms-submit-ajax-json-frontend

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Jul 4, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link

jp-launch-control bot commented Jul 4, 2025

Code Coverage Summary

Coverage changed in 6 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form.php 588/1063 (55.32%) -2.21% 46 💔
projects/packages/forms/src/modules/form/view.js 0/194 (0.00%) 0.00% 39 💔
projects/packages/forms/src/modules/form/shared.js 0/30 (0.00%) 0.00% 3 ❤️‍🩹
projects/packages/forms/src/modules/file-field/view.js 0/163 (0.00%) 0.00% 2 ❤️‍🩹
projects/packages/forms/src/contact-form/class-contact-form-field.php 601/1026 (58.58%) -0.06% 1 ❤️‍🩹

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

*/
private static function render_ajax_success_wrapper( $form ) {
$html = '<div class="contact-form-submission contact-form-ajax-submission" data-wp-class--is-submitted="state.hasSubmitted"';
$html .= '<p class="go-back-message"> <a class="link" href="#" data-wp-on--click="actions.goBack">' . esc_html__( 'Go back', 'jetpack-forms' ) . '</a> </p>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the CSS classes these for backwards compatibility, or would it make sense to add jetpack- prefix to scope them better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are for backwards compatibility, yes. That is almost a copy of the current post-submission screen.


if ( 'message' === $form->get_attribute( 'customThankyou' ) ) {
$raw_message = wpautop( $form->get_attribute( 'customThankyouMessage' ) );
// Add more allowed HTML elements for file download links
Copy link
Member

@simison simison Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why be restrictive here at all instead of just using wp_kses()'s default restrictions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the current implementation on the post-submission screen. The idea is to match it as well as possible, so I copied it over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense then 👍

} else {
$html .= '<template data-wp-each--submission="state.getSubmissionData">
<div class="field-name" data-wp-text="context.submission.label" data-wp-bind--hidden="!context.submission.label"></div>
<div class="field-value" data-wp-text="context.submission.value"></div>
Copy link
Member

@simison simison Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as https://github.com/Automattic/jetpack/pull/44204/files#r2189419246 — any reason not to prefix class with jetpack-? This one is particularly generic and can collide with theme/other plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can prefix them, yes. I just need to make sure the prefixed classes also work on the current screen. Will add it in this PR.

@dhasilva dhasilva force-pushed the update/forms-submit-ajax-json-frontend branch from 4318546 to c0bf111 Compare July 9, 2025 15:29
@dhasilva dhasilva added the [Status] Needs Review This PR is ready for review. label Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Feature] Contact Form [Package] Forms [Status] Needs Review This PR is ready for review. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants