Webform. Sergey Shumskiy

Webform is a module for creating forms and questionnaires in Drupal. After sending the letter, emails can be sent to administrator and / or to sender. The results can be exported to Excel or to other spreadsheet. Webform also provides some basic statistical reviews and it has a large API to expand its capabilities.

In this report I want to cover:

Configuring elements webform while working with file

Creating a file with .pdf format

Using webform to send a letter with datas

Advanced options for element Select

1. Configuring elements webform while working with file

For working with elements file in webform, you need to have certain settings. When configuring the Drupal 8 site, perform the following settings from file: drupal8 / core / INSTALL.txt, see step 5.

b. Open your settings.php in a plain-text editor, and uncomment (remove the #

at the start of line) this line:

# $settings['file_public_path'] = 'sites/default/files';

Enter the desired path and save the file.

If you want to use private file storage, you need to uncomment (remove

the # at the start of line) the following line in settings.php:

# $settings['file_private_path'] = '';

Enter the path for private files and save the file.

Also please pay attention to the settings in the webform itself. To do this, go to /admin/structure/webform, the Settings tab, find the section File upload default settings and check the settings as shown in the figure below.

After that, you will be able to add elements to your form webform File

2. Creating a file with .pdf format

In this project for creation a *.pdf file, I converted HTML to PDF using Dompdf. For this we need to install dompdf library (https://github.com/dompdf/dompdf ).

How did I convert HTML to PDF using Dompdf? - It's very simple, we use the following function:

Here I use the form element. In this element I "put" a link to the created file, which is stored on the server.

With the help of $form_state->setValue('form_result', $file->id()); I use the setting of my webform and the link is added to the file in the letter by itself.

Let me please summarize the results:

Received an array with all the form data

Created a unique name

Created a template and passed the data to the template

Received html data

Used Dompdf and received a * .pdf

Saved file format * .pdf

Transferred the link to the file

3. Using webform to send a letter with datas

What I mean ?

The idea is simple - I used the webform itself, since there are settings already in Emails / Handlers for my webform, I just create another field of the file format, then "hide" this field from the user and after creating the necessary * .pdf (described above), I add this file to the "hidden" field.