提交表单后保持advcheckbox检查

I am unable to keep selected checkboxes checked after form submission. After the submit button is clicked the data is submitted into to the database, but upon entering edit form mode, all check boxes are once again unchecked.

foreach ($domains as $domain){ //$domains is an array of int's
if($domain){$status = 1;
$mform->addElement('advcheckbox', 'domain_' . $domain->id,'' , $domain->rawname, array('group' => 1),  array(0, $domain->id), array(0, $status))}};

My understanding is the 6th parameter, which currently contains array(0, $status) controls the checked and unchecked status of the checkbox. $status should have the value of 1 if $domain exists, which should render the checkbox checked and stay checked. This does not happen. Any help would be appreciated!

your actual code should include $mform->set_data, but if you need a quick fix, that will be:

foreach ($domains as $domain){ //$domains is an array of int's
    $status = $domain ? 1 : 0;
    $mform->addElement('advcheckbox', 'domain_' . $domain->id, '' , $domain->rawname, array('group' => 1));
    $mform->setDefault('domain_' . $domain->id, $status);
}