Forum


Replies: 3   Views: 612
Enable checkbox with phpdocx_structureddocumenttag
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 11-05-2023 - 11:54

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.