Skip to content
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

Forms: Fix form submissions across pages that have pagination applied #41407

Merged
merged 6 commits into from
Feb 6, 2025

Conversation

enejb
Copy link
Member

@enejb enejb commented Jan 29, 2025

Fixes #41334

Currently if you create a page and split it up using the block or code.
Forms on pages other then the first one will not work. See issue #41334.

Proposed changes:

  • Add a hidden page field that lets the form know what page we are on.
  • Update the links that appear in the email as well as the form reponses linking to the correct page form.

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?

no

Testing instructions:

  • Load this PR.
  • Create a page with multiple pages.
  • Place forms across multiple pages.
  • Notice that you are able to submit each of the posts across the different pages.

@enejb enejb added [Type] Bug When a feature is broken and / or not performing as intended [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Team Review Your teammate needs to review this PR. [Package] Forms labels Jan 29, 2025
@enejb enejb requested a review from a team January 29, 2025 22:46
@enejb enejb self-assigned this Jan 29, 2025
Copy link
Contributor

github-actions bot commented Jan 29, 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 WordPress.com Simple 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, and enable the fix/form-submit-miulti-page branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack fix/form-submit-miulti-page
    

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

@github-actions github-actions bot added [Feature] Contact Form [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Jan 29, 2025
Copy link
Contributor

github-actions bot commented Jan 29, 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 Team 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 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? 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 semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for none scheduled (scheduled code freeze on undefined).

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

Copy link
Contributor

github-actions bot commented Jan 29, 2025

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 111/836 (13.28%) -0.10% 6 💔
projects/packages/forms/src/contact-form/class-contact-form.php 530/760 (69.74%) -0.36% 6 💔
projects/packages/forms/src/contact-form/class-admin.php 0/778 (0.00%) 0.00% -3 💚
projects/packages/forms/src/class-wpcom-rest-api-v2-endpoint-forms.php 0/289 (0.00%) 0.00% -5 💚

Full summary · PHP report · JS report

@simison simison changed the title Forms: Fix form submittions across pages that have pagination implemented. Forms: Fix form submissions across pages that have pagination applied Jan 30, 2025
edanzer
edanzer previously approved these changes Jan 30, 2025
Copy link
Contributor

@edanzer edanzer left a comment

Choose a reason for hiding this comment

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

I duplicated the original issue on trunk, and confirmed that the issue is fully resolved with this PR. Forms on paginated posts now submit accurately.

The code changes seem to make sense. Added a few notes. I still lack some context on the surrounding code and logic, and was trying to think through backwards compatibility issues or edge cases in how pagination works. I can't identify specific concerns other than those I've already commented on.

@enejb
Copy link
Member Author

enejb commented Jan 30, 2025

@edanzer Can you take another look? I addressed all the issue you found. :)

@simison simison requested a review from a team January 31, 2025 13:40
@@ -774,7 +780,7 @@ public function grunion_manage_post_column_response( $post ) {
echo '<div class="feedback_response__item-value">' . esc_html( $content_fields['_feedback_ip'] ) . '</div>';
}
echo '<div class="feedback_response__item-key">' . esc_html__( 'Source', 'jetpack-forms' ) . '</div>';
echo '<div class="feedback_response__item-value"><a href="' . esc_url( get_permalink( $post->post_parent ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html( get_permalink( $post->post_parent ) ) . '</a></div>';
echo '<div class="feedback_response__item-value"><a href="' . esc_url( $url ) . '" target="_blank" rel="noopener noreferrer">' . esc_html( $url ) . '</a></div>';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think changes in this file are new since last time I reviewed. Good to include. Links under Feedback now link to the correct page where the form submission originated.

edanzer
edanzer previously approved these changes Jan 31, 2025
Copy link
Contributor

@edanzer edanzer left a comment

Choose a reason for hiding this comment

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

Retested and still working great. Issues addressed. Good addition to update links in the Feedback list so they go to right page.

@@ -123,7 +123,7 @@ public function __construct( $attributes, $content = null ) {
if ( ! isset( $attributes['id'] ) ) {
$attributes['id'] = '';
}
$attributes['id'] = $attributes['id'] . '-' . ( count( self::$forms ) + 1 );
$attributes['id'] = $attributes['id'] . '-' . ( count( self::$forms ) + 1 ) . '-' . $page;
Copy link
Contributor

Choose a reason for hiding this comment

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

page isn't an object here? should we use https://developer.wordpress.org/reference/functions/get_the_id/ instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

$page is a WP global that is a number and tells WP that page to show.

@simison simison force-pushed the fix/form-submit-miulti-page branch from 09f25e0 to 1f84eb8 Compare February 4, 2025 08:37
@simison
Copy link
Member

simison commented Feb 4, 2025

rebased

simison
simison previously approved these changes Feb 4, 2025
Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

Did a basic test, and this seems to work well:

  • Two forms separated by a page break
  • Two forms on a single page without page break
  • Three forms, first and 2nd separated by page break
    image

Everything submits correctly and multiple forms appearing on the same page get individual IDs.

I noticed that when two forms are separated by page break, first from on both pages gets ID by page ID id="contact-form-950", i.e. there are two forms with the same ID on the "same page", just separated by the page break. Not an issue now and things still work as we intended, but this just highlights how we need to later work on true unique IDs.

Correct source URL shows up in the email as well:

Screenshot 2025-02-04 at 13 14 21

@simison
Copy link
Member

simison commented Feb 4, 2025

This entry_page appearing in the form response looks like it doesn't belong. It can be removed entirely, or if needed, it could be moved to "meta" section:

Screenshot 2025-02-04 at 10 58 32

In the classic view, I don't see it:

Screenshot 2025-02-04 at 10 59 26

I do see it in the export:

image

@enejb
Copy link
Member Author

enejb commented Feb 5, 2025

Good catch on the entry_page will work on removing this from the export and the new field.

@enejb enejb dismissed stale reviews from simison and edanzer via e22633e February 5, 2025 22:52
@enejb
Copy link
Member Author

enejb commented Feb 5, 2025

@simison Can you take another look when you have the chance. Thank you!

Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

Tests well now!

@simison simison added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Team Review Your teammate needs to review this PR. labels Feb 6, 2025
@enejb enejb merged commit 1e3c985 into trunk Feb 6, 2025
65 checks passed
@enejb enejb deleted the fix/form-submit-miulti-page branch February 6, 2025 20:00
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Feb 6, 2025
@zinigor zinigor added this to the jetpack/14.4 milestone Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Bug When a feature is broken and / or not performing as intended [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.

Form Block: Only the first form works if multiple forms have page breaks in between
5 participants