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 thevalueattribute 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 aselectedfunction 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’selectedfunction.selected( trim( $meta_value ), trim( esc_attr( $field_option ) ) );-TJ
The topic ‘Issue with selected options in select fields’ is closed to new replies.