Skip to content

Commit

Permalink
Fix form submission with no name but mail (#40898)
Browse files Browse the repository at this point in the history
* Fix form submission view if name field kept empty, email entry shows in name field

* add changelog entry

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12742817066

Upstream-Ref: Automattic/jetpack@e808340
  • Loading branch information
ntsekouras authored and matticbot committed Jan 13, 2025
1 parent 129d47b commit e725e0c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is an alpha version! The changes listed here are not final.

### Fixed
- Add webpack plugin to rename RTL files to match core WP expectations.
- Fix form submission view if name field kept empty, email entry shows in name field
- Forms: Fix success message color inside a dark Cover block
- Forms: Update default URL field label to match front-end

Expand Down
5 changes: 1 addition & 4 deletions src/contact-form/class-contact-form-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
$fields_array = array_keys( $all_values );
}
$lines = array_filter( explode( "\n", $chunks[0] ) );
$lines = array_filter( explode( "\n", $chunks[0] ) );
} else {
$fields_array = preg_replace( '/.*Array\s\( (.*)\)/msx', '$1', $content );

Expand Down
8 changes: 8 additions & 0 deletions src/contact-form/class-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ public static function get_compiled_form( $feedback_id, $form ) {

if ( $meta_key ) {
if ( isset( $content_fields[ "_feedback_{$meta_key}" ] ) ) {
if ( 'name' === $type ) {
// If a form contains both email and name fields but the user doesn't provide a name, we don't need to show the name field
// in the success message after submision. We have this specific check because in the above case the `author` field gets
// a fallback value of the provided email and is used in the backend in various places.
if ( isset( $content_fields['_feedback_author_email'] ) && $content_fields['_feedback_author'] === $content_fields['_feedback_author_email'] ) {
continue;
}
}
$value = $content_fields[ "_feedback_{$meta_key}" ];
}
} else {
Expand Down

0 comments on commit e725e0c

Please sign in to comment.