Automattic / Automattic/jetpack

Forms: form validation does not work when JavaScript is disabled

Open
#41,942 4 comments 0 reactions 0 assignees View on GitHub
[Block] Form [Feature] Forms [Focus] Accessibility [Package] Forms [Plugin] Jetpack [Pri] Low [Status] Auto-allocated Bug Triaged
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impacted plugin

Jetpack

### Quick summary

The Form block (and possibly shortcode) usually performs JavaScript form validation. See the [accessible-form.js](https://github.com/Automattic/jetpack/blob/trunk/projects/packages/forms/src/contact-form/js/accessible-form.js) file.

There's also a lot of PHP code for form validation, which is (I assume) for when JavaScript is disabled. See the `Contact_Form_Field->validate` method:
https://github.com/Automattic/jetpack/blob/7a3559d2f7bd0cd8915902a4d0f315167793e5cd/projects/packages/forms/src/contact-form/class-contact-form-field.php#L204-L266

This PHP validation doesn't seem to work, at least on a block theme. Submitting a form that has validation errors sends the user to a 404 page.

If this needs to be supported, then it looks like something to be fixed. Alternatively, the code could be removed if form validation with JS disabled isn't a feature that needs to be kept.

### Steps to reproduce

1. Create a form with at least one required field in a post and view the post
2. In the browser dev tools, disable JS then reload the page to make sure that take effect
3. Submit the form

Expected: The form shows validation errors
Actual: A 404 page is shown. This seems to be because `?page=1` is appended to the URL.
Image

### Site owner impact

Fewer than 20% of the total website/platform users

### Severity

Minor

### What other impact(s) does this issue have?

No revenue impact

### If a workaround is available, please outline it here.

_No response_

### Platform (Simple and/or Atomic)

Self-hosted

Contributor guide

Open the contributing guide

Research direction

Reproduce the form submission with JavaScript disabled, then inspect projects/packages/forms/src/contact-form/class-contact-form-field.php, especially Contact_Form_Field->validate, alongside projects/packages/forms/src/contact-form/js/accessible-form.js. Trace why the validation response appends ?page=1 and reaches a 404; done means invalid forms show their validation errors without JavaScript, or the repository documents that this behavior is intentionally unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php, wordpress
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.