MyBB Community Forums

Full Version: Creating a select box in plugin settings?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I was recently reading this article from MyBB Documentation that briefly describes how we can add new setting groups to mybb and then settings to those setting groups.

I copied the exact code from the first code block at this page and pasted it inside the _install() function of one of my own plugins. Also I added the code from the second code block on this page to the _uninstall() function of my plugin.

On Installing and activating the plugin, new settings group appeard on the 'Board Settings' page just fine. When I clicked on it, first three settings which are a 'yesno', 'text', and 'textarea' respectively rendered just fine. But the fourth one that is a select box did not render. Also a warning was shown near the top of the page.

Here is a screenshot that shows this situation.
[attachment=29951]
For the sake of quick reference, here is the code for rendering this select box.

        $myplugin_setting = array(
        'name' => 'myplugin_setting4',
        'title' => 'Another random setting for MyPlugin',
        'description' => 'This is a select box.',
        'optionscode' => 'select default=Default one=Option One two=Option Two three=Option Three',
        'value' => 'default',
        'disporder' => '4', 
        'gid' => intval($gid));
    $db->insert_query('settings', $myplugin_setting); 

It looks like from the warning message that there is some problem in parsing the 'optionscode'. But I am unable to find any information about the expected format for the value of this key in the MyBB dcumentation. Can you please guide me about the real error and how I can correct it?

Thanks!!
Try adding each option to new line, like this:
'optionscode' => 'select 
default=Default 
one=Option One 
two=Option Two 
three=Option Three',
(2013-08-15, 10:36 AM)Destroy666 Wrote: [ -> ]Try adding each option to new line, like this:
'optionscode' => 'select 
default=Default 
one=Option One 
two=Option Two 
three=Option Three',

Thanks, It worked. Placing \n after each option also works. I mean, this:
'optionscode' => 'select\ndefault=Default\none=Option One\ntwo=Option Two\nthree=Option Three',
and this:
'optionscode' => 'select \ndefault=Default \none=Option One \ntwo=Option Two \nthree=Option Three',
both work.
So it probably means MyBB explodes the string on '\n' as separator between options??