Issue with selected options in select fields
-
Found a slight issue with 3.9.8 with
<select>
fields. Not so much a “bug” as allowing for bunk user input. If a user provides a list of comma separated options, they are probably going to put spaces of the commas. I’ve noticed in 3.9.8 that this will cause issue with the<option>
not being selected in the<select>
field because thevalue
attribute of the<option>
actually contains a space and the comparison value does not. Basically the value is being trimmed somewhere and not somewhere else. My solution was to re-trim these values when going the actual comparison when outputting theselected="selected"
attribute (ln 304 ofregister-plus-redux.php
). A better solution is probably to consistently trim/do not trim when the data is being written to the DB, but this is a band-aid solution. Also, WordPress provides aselected
function that handles the outputting of theselected="selected"
attribute based on conditions, might as well toss that in there. I replaced ln 304 with the below which addresses the trimming issue and utilizes WordPress’selected
function.selected( trim( $meta_value ), trim( esc_attr( $field_option ) ) );
-TJ
https://www.ads-software.com/extend/plugins/register-plus-redux/
- The topic ‘Issue with selected options in select fields’ is closed to new replies.