Forum


Replies: 3   Views: 387
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 parasell  · 11-05-2023 - 11:04

I am having an issue generating a checkbox using phpdocx_structureddocumenttag.

The attribute data-checked is not working as it should. I am using Premium v12.0

Tried 

data-checked="checked"

data-checked="unchecked"

data-checked="true"

data-checked="false"

But in all cases, I get an empty unchecked checkbox.

Any advice on this? 

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.

Posted by parasell  · 12-05-2023 - 14:39

Thank you. That did the job.

Regards

Posted by borisjer  · 19-05-2023 - 18:29

Deleted by borisjer · 19-05-2023 - 19:12