See this post can help you.
I am using like this on my project.
types = array( '1' => checkbox1, '2' => checkbox2 ) $typeitem = array(); foreach ($types as $key => $value) { $typeitem[] = &$mform->createElement('advcheckbox',$key, '', $value, array('name' => $key,'group'=>1), $key); $mform->setDefault("types[$key]", true); } $mform->addGroup($typeitem, 'types',get_string('types')); $this->add_checkbox_controller(1);I hope this can help you.