Hello,
Please apply the following change in your phpdocx 12 license:
- Edit HTMLExtendedContent.php (classes folder in the classic package or Classes\Phpdocx\Transform folder in the namespaces package)
- In the getContent method go to the following line:
case 'addStructuredDocumentTag':
and add the following lines:
if (isset($attributes['checked'])) {
if ($attributes['checked'] == 'false' || $attributes['checked'] == '0') {
$attributes['checked'] = false;
} else {
$attributes['checked'] = true;
}
}
Instead of:
case 'addStructuredDocumentTag':
$wordFragment->$method($attributes['type'], $attributes);
break;
The code updated is:
case 'addStructuredDocumentTag':
if (isset($attributes['checked'])) {
if ($attributes['checked'] == 'false' || $attributes['checked'] == '0') {
$attributes['checked'] = false;
} else {
$attributes['checked'] = true;
}
}
$wordFragment->$method($attributes['type'], $attributes);
break;
After this change, you can enable and disable the checkbox using phpdocx_structureddocumenttag:
$html = '<phpdocx_structureddocumenttag data-type="checkbox" data-checked="true" />';
$docx->embedHTML($html, array('useHTMLExtended' => true));
Also please note that you can add checkboxes using the input HTML tag:
$html = '<input type="checkbox" checked>';
Regards.