Add a group of checkbox so that multiple value can be stored in database

Add a group of checkbox so that multiple value can be stored in database

by deepak saini -
Number of replies: 1

I want to store multiple checkboxes value in the database , currently only last checkbox value i.e. demo3 is stored when selecting it. Other values are not going in database .

    $preprocedure=array(); 
    $preprocedure[] =  $mform->createElement('advcheckbox', 'preprocedure','', 'Demo1', array('group' => 1), array('','demo1'));
    $preprocedure[] =  $mform->createElement('advcheckbox', 'preprocedure','', 'Demo2', array('group' => 1), array('','demo2'));
    $preprocedure[] =  $mform->createElement('advcheckbox', 'preprocedure','', 'Demo3', array('group' => 1), array('','demo3'));
   $mform->addGroup($preprocedure, 'preprocedure', get_string('preprocedure', 'assignsubmission_metadata'),array('<br>'), false);

Average of ratings: -
In reply to deepak saini

Re: Add a group of checkbox so that multiple value can be stored in database

by Yousuf Tafhim -

Try it like this. The result will come as an array.

$preprocedure=array(); 
    $preprocedure[] =  $mform->createElement('advcheckbox', 'preprocedure[]','', 'Demo1', array('group' => 1), array('','demo1'));
    $preprocedure[] =  $mform->createElement('advcheckbox', 'preprocedure[]','', 'Demo2', array('group' => 1), array('','demo2'));
    $preprocedure[] =  $mform->createElement('advcheckbox', 'preprocedure[]','', 'Demo3', array('group' => 1), array('','demo3'));
   $mform->addGroup($preprocedure, 'preproceduregroup', get_string('preprocedure', 'assignsubmission_metadata'),array('<br>'), false);