Nav apraksta

Sample_33_FormField.php 1.1KB

123456789101112131415161718192021222324252627
  1. <?php
  2. include_once 'Sample_Header.php';
  3. // New Word document
  4. echo date('H:i:s'), ' Create new PhpWord object', EOL;
  5. $phpWord = new \PhpOffice\PhpWord\PhpWord();
  6. $phpWord->getProtection()->setEditing('forms');
  7. $section = $phpWord->addSection();
  8. $textrun = $section->addTextRun();
  9. $textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput '));
  10. $textrun->addFormField('textinput')->setName('MyTextBox');
  11. $textrun->addText(htmlspecialchars(', checkbox '));
  12. $textrun->addFormField('checkbox')->setDefault(true);
  13. $textrun->addText(htmlspecialchars(', or dropdown '));
  14. $textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3'));
  15. $textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.'));
  16. $section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.'));
  17. $section->addFormField('textinput')->setValue('Your name');
  18. // Save file
  19. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  20. if (!CLI) {
  21. include_once 'Sample_Footer.php';
  22. }