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

Form data is not persisted when validation is not met #100

Open
1 task done
MaxwellGarceau opened this issue Jan 1, 2025 · 1 comment
Open
1 task done

Form data is not persisted when validation is not met #100

MaxwellGarceau opened this issue Jan 1, 2025 · 1 comment
Labels
type:bug Something isn't working. type:enhancement New feature or request.
Milestone

Comments

@MaxwellGarceau
Copy link
Collaborator

Is your enhancement related to a problem? Please describe.

When filling out a form, if a user does not pass a validation check then the entire form will be lost. This is with JavaScript support enabled.

form-data-lost-on-validation-fail.mov

Designs

Non JavaScript solution - will work with or without JS

We can repopulate the <input> fields on failed submission with the submitted value from the $_POST variable in the mailchimp_form_field function.

JavaScript is enabled (optional)

  • Option 1: We can store the in progress form data in local storage
  • Option 2: We can validate form submissions on the FE to avoid clearing form data when it hits the BE

Describe alternatives you've considered

Considering that a user could become frustrated and leave without re-attempting form submission I think this is worth fixing.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@MaxwellGarceau
Copy link
Collaborator Author

MaxwellGarceau commented Jan 10, 2025

Bug found

Found on #61

Update: The option to include JS support enqueues a script that is supposed to only clear the data on invalid form submission. That means existing functionality is not working as expected. However, the JS support option does not explicitly promise data persist on form submission so it's more of a "soft" bug.

// See if we're successful, if so, wipe the fields
const reg = /class="|'mc_success_msg"|'/i;
if (reg.test(data)) {
$('#mc_signup_form').each(function () {
this.reset();
});
$('#mc_submit_type').val('js');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working. type:enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants