Skip to content

Conversation

vianasw
Copy link
Contributor

@vianasw vianasw commented Sep 4, 2025

Fixes FORMS-247

Proposed changes:

  • I've added a toggle in the form's block panel to allow users to not save form submissions in wp-admin. The toggle is on by default.
Screenshot 2025-09-04 at 16 53 47

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:

  • Add a form to a post or page.
  • Go to the forms block settings' Manage responses panel and set the Save response toggle off.
  • Publish the post/page and then submit a form response.
  • The post-submission page will show the form submission data. Also, check that after a page refresh, the form submission is still present.
Screenshot 2025-09-08 at 11 54 28 * Go to the Jetpack Forms responses page in wp-admin and check that the response you submitted doesn't show up there. * Check that you've received an email with the form submission data. The email shouldn't have the `View in dashboard` button and the `Mark as spam` link. Screenshot 2025-09-08 at 11 50 07 * Go back to edit the post/page you've created and now set the `Save responses` toggle on. * Check that now the responses show up in the Jetpack forms responses page in wp-admin. * Check that on the post-submission page, the form submission data appears after page refresh. * Check that the form submission email shows the `View in Dashboard` button and `Mark as spam` link. Screenshot 2025-09-08 at 11 50 15 * Set up a form integration, such as MailPoet, and check that the integration continues to work with the `Save response` toggle on and off.

@vianasw vianasw requested a review from a team September 4, 2025 14:56
@github-actions github-actions bot added [Block] Contact Form Form block (also see Contact Form label) [Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Sep 4, 2025
Copy link
Contributor

github-actions bot commented Sep 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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: October 7, 2025
    • Code freeze: October 6, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@vianasw vianasw added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Sep 4, 2025
@github-actions github-actions bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Sep 4, 2025
Copy link
Contributor

@CGastrell CGastrell left a comment

Choose a reason for hiding this comment

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

While the main goal of the PR works fine, it carries a side effect: the confirmation message is not showing any of the submitted data:

Before:
image

After:
image

@CGastrell
Copy link
Contributor

I think the same happens to emails:

image image

@simison
Copy link
Member

simison commented Sep 5, 2025

Just listing aspects to take into account:

  • Summary on page after submitting working (both ajax and ajax turned off with add_filter( 'jetpack_forms_enable_ajax_submission', '__return_false' ); although I'm not sure if we want to keep the filter long term. This can be figured out in later PRs if we gate the feature with filter, as for CIAB newsletter subscription forms we won't be needing a summary either.
  • Submission visible in email (pending email toggle which disables entire email, which needs to work independently)
  • Submission in wp-admin gone with the toggle, remains with toggle disabled (as is the default)
  • Integrations continue working; particularly MailPoet integration
  • Submission gone from both exports; Google sheets and CSV. Assuming that just works with submission gone in wp-admin.

Overall, I recommend feature-gating and working through issues in separate PRs.

Would it be too much if we stored the submission temporarily for all things to work, and then removed the submission? Seems a bit wrong. 😅

@vianasw vianasw force-pushed the add/forms-store-submissions-toggle branch from 4f8c0fc to 399bd6d Compare September 5, 2025 17:33
Copy link
Contributor

github-actions bot commented Sep 5, 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 add/forms-store-submissions-toggle branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-store-submissions-toggle

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

jp-launch-control bot commented Sep 5, 2025

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/blocks/shared/components/jetpack-manage-responses-settings.js 0/4 (0.00%) 0.00% 2 ❤️‍🩹
projects/packages/forms/src/contact-form/class-contact-form.php 587/1089 (53.90%) 0.51% 1 ❤️‍🩹
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 424/1303 (32.54%) 0.63% 0 💚

Full summary · PHP report · JS report

@vianasw
Copy link
Contributor Author

vianasw commented Sep 8, 2025

While the main goal of the PR works fine, it carries a side effect: the confirmation message is not showing any of the submitted data:

Before: image

After: image

Sorry, the PR wasn't ready for testing yet. I've addressed the email and post-submission page issues now.

@vianasw
Copy link
Contributor Author

vianasw commented Sep 8, 2025

Just listing aspects to take into account:

  • Summary on page after submitting working (both ajax and ajax turned off with add_filter( 'jetpack_forms_enable_ajax_submission', '__return_false' ); although I'm not sure if we want to keep the filter long term. This can be figured out in later PRs if we gate the feature with filter, as for CIAB newsletter subscription forms we won't be needing a summary either.
  • Submission visible in email (pending email toggle which disables entire email, which needs to work independently)
  • Submission in wp-admin gone with the toggle, remains with toggle disabled (as is the default)
  • Integrations continue working; particularly MailPoet integration
  • Submission gone from both exports; Google sheets and CSV. Assuming that just works with submission gone in wp-admin.

Overall, I recommend feature-gating and working through issues in separate PRs.

Would it be too much if we stored the submission temporarily for all things to work, and then removed the submission? Seems a bit wrong. 😅

I've addressed the issues with the email and post-submission page in a way that I think won't be necessary to store the submission temporarily.

@simison simison requested a review from CGastrell September 8, 2025 11:34
@simison
Copy link
Member

simison commented Sep 8, 2025

I tested and overall works well; the

  • When disabled, the message didn't get stored, and the submission confirmation and email looked fine
  • Without this PR, I tested that MailPoet integration worked
    Screenshot 2025-09-08 at 14 32 20
  • With this PR, I didn't get MailPoet integration work, but I think the message might've gotten caught in spam, since I didn't get an email either. In that case, perhaps we should let the submission store in Spam (where it'll get automatically removed in 2 weeks)? Once spam is approved, the message would still not get stored, but the integration would work in just like the email now works.
  • Should we hide the "manage" button when toggle is disabled? Fine to polish design with Ilona later this week and to do in a follow-up.
    Screenshot 2025-09-08 at 14 24 49

I've added a toggle in the form's block panel to allow users to not save
form submissions in wp-admin. The toggle is on by default.
Due to shortcode bacwkard render compability, we need to store the
saveResponses attribute as a 'yes'/'no' string attribute.
This commit addresses issues in the contact form email functionality
when the "Save responses" toggle is disabled. The changes ensure that:

1. Method signature enhancement: Added an optional $response parameter
   to get_compiled_form_for_email() to allow passing response data
   directly instead of always fetching from database
2. Conditional response fetching: Modified the method to only fetch
   response from database when not provided as parameter, preventing
   errors when no feedback ID exists
3. Defensive URL building: Added checks before building dashboard URLs
   and spam marking URLs to handle cases where $post_id is null (when
   responses aren't saved)
4. Conditional metadata storage: Added guard clause to prevent storing
   feedback email metadata when no post ID exists
5. Safe nonce generation: Added null check when generating nonces to
   avoid issues with missing post IDs
6. Action button handling: Made the "View in dashboard" action button
   conditional on having a valid dashboard URL

These changes ensure the email notification system works properly
regardless of whether form responses are being saved to the database or
not.
* Added $expected_attributes['saveResponses'] = 'yes'; to the expected
  attributes in the test.
I deleted too much during the rebase conflict resolution.
- Add test_process_submission_stores_feedback_when_save_responses_yes()
  Tests that form submissions are stored when saveResponses='yes'
- Add
  test_process_submission_does_not_store_feedback_when_save_responses_no()
  Tests that form submissions are NOT stored when saveResponses='no'
- Add
  test_process_submission_stores_feedback_when_save_responses_default()
  Tests that form submissions are stored by default (saveResponses
  defaults to 'yes')

These tests ensure the saveResponses attribute properly controls whether
form submissions are stored in the WordPress database while maintaining
email functionality regardless of the setting.
@vianasw vianasw force-pushed the add/forms-store-submissions-toggle branch from dda00a3 to 1c5cd16 Compare September 8, 2025 12:03
- Move status determination logic from Feedback::save() to
  Contact_Form::process_submission()
- Centralize all status logic (trash, spam, temp, publish) in one
  location
- Remove form reference from Feedback class as it's no longer needed
- Improve code organization by keeping status logic with form processing
- Maintain existing functionality while improving maintainability

The temp status is now determined early in the form processing flow
and passed to the Feedback object, creating a cleaner separation
of concerns between form processing and data persistence.
- Remove redundant $post_id check when updating unread feedback count
- Update dashboard URL condition to check feedback_status instead of
  $post_id
- Ensures proper handling of temporary feedback posts when form
  submissions are not stored # Please enter the commit message for your
  changes. Lines starting
In the backend we have to live with the 'yes'/'no' string because of the
shortcode legacy reason but we don't have to in the block attribute.
This way we'd have to just refactor the backend if we move away from the
shortcode-mangled way of doing things.
Copy link
Contributor

@CGastrell CGastrell left a comment

Choose a reason for hiding this comment

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

Worked well on all cases, including MailPoet integration even without saving the response. I left a comment for your consideration, but otherwise LGTM! :shipit:

@@ -279,6 +279,21 @@ protected function __construct() {
)
);

// Add "temp" as a post status for temporary storage when saveResponses is 'no'
register_post_status(
'temp',
Copy link
Contributor

Choose a reason for hiding this comment

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

This worked fine, I just wonder if we should purposely use a less common word. After all, this will live both on dotcom and on any self hosted, we need to make sure the post status registration doesn't fail because there was already one there with the same name. I'd use some more complex, like jetpack-temp-feedback or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hum, good point. I'll give it a try.

// translators: The temporary count.
'label_count' => _n_noop( 'Temporary <span class="count">(%s)</span>', 'Temporary <span class="count">(%s)</span>', 'jetpack-forms' ),
'protected' => true,
'_builtin' => false,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to do this. Since this is the default for '_builtin' is false;

Can we also set internal to true. So that the status work more as expected.
It then future setting will be more align with what we expected.

Such as show_in_admin_status_list - see https://developer.wordpress.org/reference/functions/register_post_status/

'exclude_from_search' => true,
'show_in_admin_all_list' => false,
// translators: The temporary count.
'label_count' => _n_noop( 'Temporary <span class="count">(%s)</span>', 'Temporary <span class="count">(%s)</span>', 'jetpack-forms' ),
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this. Not sure where it would show up. Since we should be hiding it.

@@ -2076,15 +2099,14 @@ public function process_submission() {
'contact-form-id' => $id,
'contact-form-sent' => $post_id,
'contact-form-hash' => $this->hash,
'_wpnonce' => wp_create_nonce( "contact-form-sent-{$post_id}" ), // wp_nonce_url HTMLencodes :( .
'_wpnonce' => $post_id ? wp_create_nonce( "contact-form-sent-{$post_id}" ) : '', // wp_nonce_url HTMLencodes :( .
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this. Since we should be always setting the $post_id now.

@@ -1806,6 +1815,8 @@ public function process_submission() {
$feedback_status = 'trash';
} elseif ( $is_spam ) {
$feedback_status = 'spam';
} elseif ( 'no' === $this->get_attribute( 'saveResponses' ) ) {
$feedback_status = 'temp';
Copy link
Member

Choose a reason for hiding this comment

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

Should we always be setting to 'temp' status?

My assumtion would be that this would always happen if saveResponses is set to "no"

So even if we mark the post as "spam" we. Not sure if we need another status here. Such as "spam-temp" or something like that 🤔. I would assume no.

@@ -1861,15 +1872,17 @@ public function process_submission() {
// once insert has finished we don't need this filter any more
remove_filter( 'wp_insert_post_data', array( $plugin, 'insert_feedback_filter' ), 10 );

update_post_meta( $post_id, '_feedback_extra_fields', $this->addslashes_deep( $extra_values ) );
if ( $post_id ) {
Copy link
Member

Choose a reason for hiding this comment

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

DO we still need this check?


if ( 'publish' === $feedback_status ) {
// Increase count of unread feedback.
$unread = (int) get_option( 'feedback_unread_count', 0 ) + 1;
update_option( 'feedback_unread_count', $unread );
}

if ( defined( 'AKISMET_VERSION' ) ) {
if ( defined( 'AKISMET_VERSION' ) && $post_id ) {
Copy link
Member

Choose a reason for hiding this comment

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

The same as this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Contact Form Form block (also see Contact Form label) [Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants