Forum


Replies: 4   Views: 567
Question about adding form elements on the same line as text
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  · 20-04-2023 - 09:51

Hello,

What version of phpdocx are you using?

We have run the the following code using phpdocx 13.5:

$docx = new CreateDocx();

$content1 = new WordFragment($docx);
$content1->addText('1.1', ['font' => 'Arial', 'fontSize' => 8, 'indent_left' => 10]);

$content2 = new WordFragment($docx);
$content2->addFormElement('select', ['selectOptions' => [' 0 ', ' 1 ', ' 2 ', ' 3 ']]);

$content = array();
$content[] = $content1;
$content[] = $content2;

$item = new WordFragment($docx);
$item->addText($content);

$docx->addText(array($item));

$docx->createDocx('output.docx');

and the output is correct. Both contents appear in the same line.

Also note that you can avoid generating an extra WordFragment:

$docx = new CreateDocx();

$content1 = new WordFragment($docx);
$content1->addText('1.1', ['font' => 'Arial', 'fontSize' => 8, 'indent_left' => 10]);

$content2 = new WordFragment($docx);
$content2->addFormElement('select', ['selectOptions' => [' 0 ', ' 1 ', ' 2 ', ' 3 ']]);

$docx->addText(array($content1, $content2));

$docx->createDocx('output.docx');

Please note that adding form and structured document tags as inline contents was added in phpdocx 13.5.

Regards.