Skip to content

Commit b247392

Browse files
talldanmatticbot
authored andcommitted
Fix non rendered fields still validating and displaying response submission (#41979)
* Avoid validating non renderable fields * Prevent non-renderable fields from displaying in form submission response * changelog Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13535853444 Upstream-Ref: Automattic/jetpack@75236ed
1 parent cb595a7 commit b247392

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
This is an alpha version! The changes listed here are not final.
1111

1212
### Fixed
13+
- Forms: Ensure fields that skip rendering (like empty options fields) do not trigger validation or show value in form submission response.
1314
- Forms: Fix 404 error when a user submits an invalid form with JavaScript disabled.
1415

1516
## [0.39.0] - 2025-02-24

src/contact-form/class-contact-form-field.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,14 @@ public function is_error() {
205205
* Validates the form input
206206
*/
207207
public function validate() {
208+
$field_type = $this->maybe_override_type();
209+
208210
// If it's not required, there's nothing to validate
209-
if ( ! $this->get_attribute( 'required' ) ) {
211+
if ( ! $this->get_attribute( 'required' ) || ! $this->is_field_renderable( $field_type ) ) {
210212
return;
211213
}
212214

213215
$field_id = $this->get_attribute( 'id' );
214-
$field_type = $this->maybe_override_type();
215216
$field_label = $this->get_attribute( 'label' );
216217

217218
if ( isset( $_POST[ $field_id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- no site changes.

src/contact-form/class-contact-form.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,11 @@ public function process_submission() {
11611161
// For all fields, grab label and value
11621162
foreach ( $field_ids['all'] as $field_id ) {
11631163
$field = $this->fields[ $field_id ];
1164+
1165+
if ( ! $field->is_field_renderable( $field->get_attribute( 'type' ) ) ) {
1166+
continue;
1167+
}
1168+
11641169
$label = $i . '_' . $field->get_attribute( 'label' );
11651170
$value = $field->value;
11661171

@@ -1172,6 +1177,11 @@ public function process_submission() {
11721177
// Extra fields have their prefix starting from count( $all_values ) + 1
11731178
foreach ( $field_ids['extra'] as $field_id ) {
11741179
$field = $this->fields[ $field_id ];
1180+
1181+
if ( ! $field->is_field_renderable( $field->get_attribute( 'type' ) ) ) {
1182+
continue;
1183+
}
1184+
11751185
$label = $i . '_' . $field->get_attribute( 'label' );
11761186
$value = $field->value;
11771187

0 commit comments

Comments
 (0)