MyBB Community Forums

Full Version: FormContainer default selected option on select box.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm creating an "edit field" form for my plugin and i want to know how can i have a default selected option on it. Right now i am doing this:

Merge of $field with the $mybb->input
$mybb->input = array_merge($mybb->input, $field);

Where $field is an array with these values: name, description and definition. The last one is important because that's the one related with the select_box:
$form_container->output_row($lang->definition, "$lang->definition_desc", $form->generate_select_box('definition', array('string' => $lang->string, 'integer' => $lang->integer, 'tinyint' => $lang->tinyint, 'text' => $lang->text, 'boolean' => $lang->boolean), 'definition'));

But, even though both text_box and text_area get to display their values, the select_box stucks with the default one: "string".

How can I solve it?

Thanks in advance!

Edit: Also, i will like to ask another thing. Is there a way to use the Form and FormContainer class in my plugn's functions? I want to create a custom form using the misc_start hook but it says that those two classes are not define:

$form = new Form("misc.php?character=create", "post", "create_character");
$form_container = new FormContainer($lang->character_create);
You have a syntax issue. The third one is for selected, and the current third one (your last one) should be at fifth.

	$selected = 'tinyint'; // For example
	$id = 'my_select'; // If you wanna set one, else pass a blank array
	$select_options = array('string' => $lang->string, 'integer' => $lang->integer, 'tinyint' => $lang->tinyint, 'text' => $lang->text, 'boolean' => $lang->boolean);
	$custom_select = $form->generate_select_box('definition', $select_options, $selected, array('id' => $id), 'definition');
	
	$form_container->output_row($lang->definition, "$lang->definition_desc", $custom_select);

Or as a one-liner:

$form_container->output_row($lang->definition, "$lang->definition_desc", $form->generate_select_box('definition', array('string' => $lang->string, 'integer' => $lang->integer, 'tinyint' => $lang->tinyint, 'text' => $lang->text, 'boolean' => $lang->boolean), 'tinyint', array('id' => 'my_select'), 'definition'));

... and yes, you should surely be able to use the class once you add it in your script using require_once or include_once.