Bug #675
Checkbox setting type broken
| Status: | Deferred | Start date: | 01/13/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - | |||
| Reproducibility: | Always | Database Type: | ||
| Reported In MyBB Version: | 1.4.11 | Database Version: | ||
| PHP Version: | 5.3.0 | SQA assignments: | ||
| Browser: |
Description
This is the code I used for the optionstype bit of a settings array for a plugin:
"optionscode" => "checkbox none=None 1=One 0=Zero 2=Two 4=Four",
Inserts the setting and displays OK in the ACP, 5 check boxes. However if you select more than 1, it only actually saves the last one. For instance, if I select 'One' and 'Two', when I go back to it, only 'Two' is selected, and the value of $mybb->settings['setting'] is 2, I was expecting 1,2 or array("1", "2") or soemthing. Clearly this defeats the object of having checkboxes, if you only wanted one option you'd use radio buttons.
At first I was slightly amazed this had never been found before, but then again I can't ever remember seeing a plugin using this type of setting... whether that's because they tried it and found it was broken but didn't report it, or nobody's ever wanted to use it, I dunno...
History
#1 Updated by Chris W. B. over 2 years ago
- Status changed from New to Confirmed
#2 Updated by Tom Moore over 2 years ago
<removed>
Ignore me, blonde moment...
#3 Updated by Matt Rogowski over 2 years ago
The checkboxes option is there for me.
#4 Updated by Tom Moore over 2 years ago
I knew there was method to my madness...
The checkboxes are an option, but it's impossible (I think) to provide multi-selects through that option. For example, multi select checkboxes look like this:
<input type="checkbox" name="multi[]" value="1"> <input type="checkbox" name="multi[]" value="2"> <input type="checkbox" name="multi[]" value="3">
This then generates an array which we can pick up on. But the ACP generates the options like this:
<input type="checkbox" name="upsetting[test_setting]" value="1" class="checkbox_input setting_test_setting" id="setting_test_setting_1" /> <input type="checkbox" name="upsetting[test_setting]" value="1" class="checkbox_input setting_test_setting" id="setting_test_setting_2" /> <input type="checkbox" name="upsetting[test_setting]" value="1" class="checkbox_input setting_test_setting" id="setting_test_setting_3" />
It uses the same name, which makes it impossible to do it that way. You'll need to generate the checkboxes via the PHP option, instead of the default checkbox option, to be able to pick up the array data from them.
#5 Updated by Matt Rogowski over 2 years ago
Righto... in that case then shouldn't the checkboxes option be removed?? It doesn't work for multiple options, if you'd want a list of options and the ability to only choose 1 you'd use radio buttons, and it you wanted just one option to check/uncheck you could use the on/off or yes/no one... if it won't work for multiple options I can't think of a use for it.
#6 Updated by Dennis Tsang over 2 years ago
name="upsetting[test_setting][]"
#7 Updated by Huji Lee over 2 years ago
I think we either should follow Matt's idea, or be bold and modify ACP to allow checkboxes and multi-selection functionality.
#8 Updated by Tom Moore about 2 years ago
I wouldn't recommend updating the ACP to allow checkboxes - or remove the option - as it might cause absolute havoc and break compatibility with plugins.
If a checkbox is absolutely necessary, then the user can always create them by evaluating PHP instead.
#9 Updated by Ryan Gordon about 2 years ago
So this should be deferred for 2.0?
#10 Updated by Matt Rogowski about 2 years ago
I'd go with that.
#11 Updated by Huji Lee about 2 years ago
- Status changed from Confirmed to Deferred