-
Notifications
You must be signed in to change notification settings - Fork 808
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/invalid field ids #41564
Open
edanzer
wants to merge
3
commits into
trunk
Choose a base branch
from
fix/invalid-field-ids
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+14
−6
Open
Fix/invalid field ids #41564
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Forms: Fix invalid html IDs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -655,7 +655,7 @@ public function render_textarea_field( $id, $label, $value, $class, $required, $ | |
/** | ||
* Return the HTML for the radio field. | ||
* | ||
* @param int $id - the ID. | ||
* @param string $id - the ID (starts with 'g' - see constructor). | ||
* @param string $label - the label. | ||
* @param string $value - the value of the field. | ||
* @param string $class - the field class. | ||
|
@@ -674,11 +674,11 @@ public function render_radio_field( $id, $label, $value, $class, $required, $req | |
$option = Contact_Form_Plugin::strip_tags( $option ); | ||
if ( is_string( $option ) && $option !== '' ) { | ||
$radio_value = $this->get_option_value( $this->get_attribute( 'values' ), $option_index, $option ); | ||
$radio_id = "$id-$radio_value"; | ||
$radio_id = sanitize_html_class( $id ) . '-' . sanitize_html_class( $radio_value ); | ||
|
||
$field .= "<p class='contact-form-field'>"; | ||
$field .= "<input | ||
id='" . esc_attr( $radio_id ) . "' | ||
id='" . $radio_id . "' | ||
type='radio' | ||
name='" . esc_attr( $id ) . "' | ||
value='" . esc_attr( $radio_value ) . "' " | ||
|
@@ -745,7 +745,7 @@ private function render_consent_field( $id, $class ) { | |
/** | ||
* Return the HTML for the multiple checkbox field. | ||
* | ||
* @param int $id - the ID. | ||
* @param string $id - the ID (starts with 'g' - see constructor). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $id is always a string. See contructor around line 150 where it is set. This is relevant because a valid html ID need to start with a letter, not a number. |
||
* @param string $label - the label. | ||
* @param string $value - the value of the field. | ||
* @param string $class - the field class. | ||
|
@@ -768,11 +768,11 @@ public function render_checkbox_multiple_field( $id, $label, $value, $class, $re | |
$option = Contact_Form_Plugin::strip_tags( $option ); | ||
if ( is_string( $option ) && $option !== '' ) { | ||
$checkbox_value = $this->get_option_value( $this->get_attribute( 'values' ), $option_index, $option ); | ||
$checkbox_id = "$id-$checkbox_value"; | ||
$checkbox_id = sanitize_html_class( $id ) . '-' . sanitize_html_class( $checkbox_value ); | ||
|
||
$field .= "<p class='contact-form-field'>"; | ||
$field .= "<input | ||
id='" . esc_attr( $checkbox_id ) . "' | ||
id='" . $checkbox_id . "' | ||
type='checkbox' | ||
name='" . esc_attr( $id ) . "[]' | ||
value='" . esc_attr( $checkbox_value ) . "' " | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: bugfix | ||
|
||
Forms: Fix invalid html IDs. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to wrap
$id
with sanitize_html_class( $id ). Since if this is the case we would need to do it in a few different places as well see line 668.