MyBB Community Forums
Solved: help with the form class and specifically generate_select_box - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Solved: help with the form class and specifically generate_select_box (/thread-124382.html)



Solved: help with the form class and specifically generate_select_box - Dannymh - 2012-08-14

Hi all,

I am looking at making a select box that has a list of categories in them and will be something like

-category1
--subcategory1
---sub-subcategory1
-category2

I can generate the basic list using the following

foreach($categories as $category) {
$cat_option[] = $category["name"];
}

$category_box = $form->generate_select_box('category', $cat_option, $mybb->input['category']);

this will result in a select box with value="0", 1, 2 etc however I want these values to be $category["ID"];

How would I do this? What part of the array or what do I need to build into the array to force the value of each option, not just the display?

Cheers
Dan

I should note that when I put in an associative array of

$category = array("category1" => "category Name 1", "category2" => "category name 2");

The form field fails with an error because the foreach fails

Dan


NOTE: ok I fixed this, an associative array is the correct way to handle this, there was a typo in my create select box part Smile