WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#11111 closed defect (bug) (invalid)

HTML stripped from hand-coded select boxes after saving widget options

Reported by: sillybean Owned by: azaozz
Milestone: Priority: normal
Severity: normal Version: 2.9
Component: Widgets Keywords: widgets, ajax, javascript
Focuses: Cc:

Description

I've been having problems with some select boxes in widget options. After I save changes, my options are displayed as text rather than option fields, like so:
http://sillybean.net/downloads/widget-before-after.png

The values are stored correctly, but you can't make any further changes without reloading the widget admin page. Select boxes generated by WP functions (like wp_dropdown_categories or wp_dropdown_pages) don't seem to be affected, but hand-coded ones are -- although I can't see a difference in their HTML structures.

The ajax return (according to Firebug) looks like:

<p><label for="widget-randompostsfromcategory-3-content">Display:</label>
<select id="widget-randompostsfromcategory-3-content" name="widget-randompostsfromcategory[3][content]" />
  <option value="title" >Title Only</option>
  <option value="excerpt"  selected="selected" >Title and Excerpt</option>
  <option value="content" >Title and Content</option>
</select></p>

What actually shows up on the page:

<p><label for="widget-randompostsfromcategory-3-content">Display:</label>
<select name="widget-randompostsfromcategory[3][content]" id="widget-randompostsfromcategory-3-content"/>
Title Only
Title and Excerpt
Title and Content
</p>

For some reason the </select> tag is removed along with all the <option></option> tags.

The code above is taken from my Random Posts from Category plugin, but I've seen the same behavior in other widget plugins as well.

Change History (5)

comment:1 scribu4 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Are you sure you're using the right escape function?

Reopen if you can reproduce the error with a native widget.

comment:2 scribu4 years ago

  • Milestone Unassigned deleted

comment:3 sillybean4 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Reopening because I have never seen documentation indicating that form elements in widget options screens must be escaped. (Text, yes; form elements themselves, no.) My code looks exactly like that of the native widgets, but the select/option form fields are nevertheless incorrectly stripped.

comment:4 azaozz4 years ago

Looks like typo to me, <select> tag cannot be self-closing (like in the example).

comment:5 sillybean4 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Wow, huge IDE fail! Thanks very much for spotting that. I'll close this and let the other plugin developers know what's causing the problem.

Note: See TracTickets for help on using tickets.