how to add multiple check box in a group?

how to add multiple check box in a group?

by Amal k -
Number of replies: 2

Hi,

i found the following code from moodle form API to create checkbox. but it gives only one checkbox. I want to add three check box


$mform->addElement('advcheckbox', 'ratingtime', get_string('ratingtime', 'forum'), 'Label displayed after checkbox', array('group' => 1), array(0, 1));

Average of ratings: -
In reply to Amal k

Re: how to add multiple check box in a group?

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi.

You should probably spend some time familiarizing yourself with the way forms work in Moodle using the documentation. In particular, you are asking about the checkbox element, which you add one at a time in a form for each checkbox you need. You can also group elements together if you wish. And, there is also a way to add multiple checkboxes with a controller that allows you to select all or none of them with one click.

Mike

In reply to Amal k

how to add multiple check box in a group?

by hd7 exploit -

 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.