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

Fix form submission with no name but mail #40898

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

ntsekouras
Copy link
Member

Fixes #30456

Proposed changes:

Currently if we have a form with a name field and an email field where the name is not required, when we submit the form with an empty name, the success messages shows the name with the email value.

This happens because during submission there is code that sets the email as a fallback. That $comment_author is later on used in more places (like headers, entity title, etc..) so I didn't make any update there.

Instead in the time of rendering the success message I added a check whether name and email have the same values. In that case, we don't render the name.

Ideally we should check if the original name value was provided or not, but I couldn't find a way to get that value and I think it's not stored anywhere else, without having the fallback applied during submission.

My check though introduces a new edge case where in a form like the one described here, if a user submits an email to both name and email fields, we will not render the name in the success message.

I'd consider edge cases both the linked issue and my approach and I'm not sure if it's even worth it to handle this.

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)?

Testing instructions:

  1. In a post add a contact form
  2. make the name field not required
  3. submit the form in the front end without providing a name
  4. Observe that the name is not part of the success message
  5. Test the form with different combinations of input (ex. provide both email and name, only email, etc..).

@ntsekouras ntsekouras self-assigned this Jan 8, 2025
@ntsekouras ntsekouras added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Contact Form [Status] In Progress [Status] Needs Team Review labels Jan 8, 2025
Copy link
Contributor

github-actions bot commented Jan 8, 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 try/fix-form-submission-with-no-name-but-mail branch.

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

    bin/jetpack-downloader test jetpack try/fix-form-submission-with-no-name-but-mail
    

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 Jan 8, 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.


🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

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

My PR adds *x* and *y*.

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!

@@ -2046,10 +2046,7 @@ public static function parse_fields_from_content( $post_id ) {
if ( str_contains( $content, 'JSON_DATA' ) ) {
$chunks = explode( "\nJSON_DATA", $content );
$all_values = json_decode( $chunks[1], true );
if ( is_array( $all_values ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not related, but I observed that $fields_array is only used in the else block.

@simison simison requested a review from a team January 8, 2025 20:28
Copy link
Member

@enejb enejb left a comment

Choose a reason for hiding this comment

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

Nice work!

This now works as expected for me. See
Screenshot 2025-01-10 at 08-17-34 Enej Dev jetpack 1

Screenshot 2025-01-10 at 08-18-27 Enej Dev jetpack 1

Screenshot 2025-01-10 at 08-18-53 Enej Dev jetpack 1

My check though introduces a new edge case where in a form like the one described here, if a user submits an email to both name and email fields, we will not render the name in the success message.

I was able to confirm that this is now an edge case. I don't think we need to solve for it though.

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.

Changes look straightforward and safe, and work as expected. And confirmation looks better without outputting the email as the name.

Agree with @enejb on the edge case. I think it's fine as is.

Lots of e2e testing issues that all seem unrelated?

@ntsekouras ntsekouras force-pushed the try/fix-form-submission-with-no-name-but-mail branch from 8574e0d to 7223022 Compare January 13, 2025 07:37
@ntsekouras ntsekouras changed the title Try/fix form submission with no name but mail Fix form submission with no name but mail Jan 13, 2025
@ntsekouras ntsekouras merged commit e808340 into trunk Jan 13, 2025
59 of 60 checks passed
@ntsekouras ntsekouras deleted the try/fix-form-submission-with-no-name-but-mail branch January 13, 2025 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [Package] Forms [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form: Submission view - If name field kept empty, email entry shows in name field
3 participants