Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#20679 closed defect (bug) (worksforme)

Widget with mutliple select doesn't work

Reported by: topweb Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.2
Component: Widgets Keywords: needs-patch
Focuses: Cc:


Widget with <select multiple="multiple"> doesn't work.
To reproduce the bug you need to test the following code in a widget:

public function update($new_instance, $old_instance) {

function form($instance) { ?>
        <select multiple="multiple" name="<?php echo $this->get_field_name('options'); ?>">
                <option value="1">
                Option 1
                <option value="2">
                Option 2
        </select> <?php

Change History (8)

comment:1 @dd323 years ago

Can you add some details of what doesn't work, and how you expect that it should work?

comment:2 @johnbillion3 years ago

FWIW the multiple select element is a very poor element from a UI and UX perspective. I can guarantee you'll get users who don't know how to select multiple items in it. You might be better off replacing it with checkboxes which are much more widely used and understood.

comment:3 @topweb3 years ago

Yes here are more details:

Post parameters when saving are:

action save-widget
id_base featuredgames
savewidgets b277827e4e
sidebar left-sidebar-home-page
widget-featuredgames[2][categoriesIds] 7
widget-featuredgames[2][categoriesIds] 8
widget-height 200
widget-id featuredgames-2
widget-width 250
widget_number 2

As you can see categoriesIds should be an array from the multiple select.

I am expecting to get from the update function an array containing both submitted values:

public function update($new_instance, $old_instance) {



And it actually returns this:
Array ( [categoriesIds] => 8 )

I agree, dd32, it maybe not the best UI option but still it it's the fastest way
to achieve it...

Version 0, edited 3 years ago by topweb (next)

comment:4 @jane3 years ago

What johnbillion said. Do we have a widget with multiselect? If so, it's an oversight on my part or I would have booted it long ago for that reason. Checkboxes are the approved multi-select UI in the WP admin.

comment:5 @scribu3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

What Jane said. We do not use multiselect anywhere in WP and we should not encourage plugin authors to use them either. Checkboxes FTW.

comment:6 follow-up: @kurtpayne3 years ago

  • Cc kpayne@… added

Again, checkboxes is the way to go. Just wanted to defend the core, though. The behavior you're seeing is because you need two square brackets after a multiple select field name to tell php to treat the field as an array.

<select multiple="multiple" name="<?php echo $this->get_field_name('options'); ?>[]">

comment:7 @johnbillion3 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

comment:8 in reply to: ↑ 6 @johnbillion3 years ago

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

Replying to kurtpayne:

The behavior you're seeing is because you need two square brackets after a multiple select field name to tell php to treat the field as an array.


Note: See TracTickets for help on using tickets.