MyBB Community Forums

Full Version: Understanding $form->generate_forum_select();
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there,

currently working on a plugin that needs to create an admin settings page, where I need to be able to 'insert' through a form. 

I'm currently just debugging in Chrome, where I'm seeing this:

[Image: SidsL5W.png]
This is the 'code':
$form_container->output_row("Available Forums", "Which forums are the vote enabled in", $form->generate_forum_select("forums[]", $forumsIds->fid, array("multiple" => true), true));

Now, first of all, my knowledge of using the PHP Form Class is taken from github projects and other plugins, meaning I am uncertain of a lot of information. My bad there I know.

What I need is to know, since those inputs share same name, how do I access them via the $mybb->input['forums'] ? 

Also in the code snip above, what does 
$forumsIds->fid

this magic do ? 

Appreciate any help, since I'm still in early learning phases of MyBB development, and not really a huge PHP coder ...
I’m not sure on the fid parameter specifically, but it appears to simply be a variable that holds a list of available forums to select from.

accessing them in PHP after the form is submitted is just simply accessing the array. $mybb->input[‘forums’] as you mentioned is correct.
(2020-03-30, 06:49 PM)Darth Apple Wrote: [ -> ]I’m not sure on the fid parameter specifically, but it appears to simply be a variable that holds a list of available forums to select from.

accessing them in PHP after the form is submitted is just simply accessing the array. $mybb->input[‘forums’] as you mentioned is correct.

This is how I'm trying to do debug it, this code is run when there is a POST request:

$forumsDelim = implode(",", $mybb->input['forums[]']);

flash_message("Elements in Forums Array: ".count($forumsArr)." List of Forums: ".$forumsDelim);

And this is how the response looks:

[Image: Xj18pr0.png]

Not sure what I'm doing wrong.


EDIT !!!!!!!

So I'm not a complete retard, what was wrong wasn't my logic, it was my understanding of using PHP in a form. Anyway solution was to name the field "forums[]" but the input would then still be $mybb->input['forums'], thus it's all working now. Yay.

I will end up populating this board with commonplace questions that I'll end up answering myself, lol.