PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.15
E2Pdf – Export Pdf Tool for WordPress v1.32.15
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / extension / e2pdf-forminator.php

e2pdf-forminator.php in E2Pdf – Export Pdf Tool for WordPress 1.32.15, at classes/extension/e2pdf-forminator.php

3,519 lines 186.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /extension/e2pdf-forminator.php
5 *
6 * @package E2Pdf
7 * @license GPLv3
8 * @link https://e2pdf.com
9 */
10 if (!defined('ABSPATH')) {
11 die('Access denied.');
12 }
13
14 class Extension_E2pdf_Forminator extends Model_E2pdf_Model {
15
16 private $options;
17 private $info = array(
18 'key' => 'forminator',
19 'title' => 'Forminator Forms',
20 );
21
22 // info
23 public function info($key = false) {
24 if ($key && isset($this->info[$key])) {
25 return $this->info[$key];
26 } else {
27 return array(
28 $this->info['key'] => $this->info['title'],
29 );
30 }
31 }
32
33 // active
34 public function active() {
35 if (defined('E2PDF_FORMINATOR_EXTENSION') || $this->helper->load('extension')->is_plugin_active('forminator/forminator.php') || $this->helper->load('extension')->is_plugin_active('forminator-pro/forminator.php')) {
36 return true;
37 }
38 return false;
39 }
40
41 // set
42 public function set($key, $value) {
43 if (!isset($this->options)) {
44 $this->options = new stdClass();
45 }
46 $this->options->$key = $value;
47 switch ($key) {
48 case 'item':
49 $this->set('cached_form', false);
50 if ($this->get('item') && class_exists('Forminator_API')) {
51 $form = Forminator_API::get_form($this->get('item'));
52 if (!is_wp_error($form)) {
53 $this->set('cached_form', $form);
54 }
55 }
56 break;
57 case 'field_data_array':
58 case 'dataset':
59 $this->set('cached_entry', false);
60 $this->set('cached_meta', array());
61 $this->set('cached_data', array());
62 if ($this->get('dataset') && class_exists('Forminator_Form_Entry_Model') && $this->get('cached_form')) {
63 if ($this->get('dataset') == 'is_prevent_store') {
64 $entry = new Forminator_Form_Entry_Model();
65 $entry->set_fields($this->replace_values_to_labels($this->get('field_data_array'), $this->get('cached_form'), $entry));
66 if (isset($entry->meta_data) && is_array($entry->meta_data)) {
67 $entry->meta_data = $this->update_meta_data($entry->meta_data);
68 }
69 $this->set('cached_entry', $entry);
70 $this->set('cached_meta', $this->get('cached_entry')->meta_data);
71 } else {
72 $entry = Forminator_API::get_entry($this->get('item'), $this->get('dataset'));
73 if (isset($entry->meta_data) && is_array($entry->meta_data)) {
74 $entry->meta_data = $this->update_meta_data($entry->meta_data);
75 }
76 $this->set('cached_entry', $entry);
77 $this->set('cached_meta', $this->get('cached_entry')->meta_data);
78 }
79 $data = array();
80 foreach ($this->get('cached_meta') as $key => $meta) {
81 if (is_array($meta['value'])) {
82 if (array_unique(array_map('is_int', array_keys($meta['value']))) === array(true)) {
83 $data[$key] = $meta['value'];
84 } else {
85 if (isset($meta['value']['file']['file_url'])) {
86 $data[$key] = $meta['value']['file']['file_url'];
87 } else {
88 foreach ($meta['value'] as $sub_key => $sub_meta) {
89 $data[$key . '-' . $sub_key] = $sub_meta;
90 }
91 }
92 }
93 } else {
94 $data[$key] = $meta['value'];
95 }
96 }
97 $this->set('cached_data', $data);
98 }
99 break;
100 default:
101 break;
102 }
103 return true;
104 }
105
106 // get
107 public function get($key) {
108 if (isset($this->options->$key)) {
109 $value = $this->options->$key;
110 } else {
111 switch ($key) {
112 case 'args':
113 case 'cached_meta':
114 case 'cached_data':
115 case 'field_data_array':
116 $value = array();
117 break;
118 default:
119 $value = false;
120 break;
121 }
122 }
123 return $value;
124 }
125
126 // items
127 public function items() {
128 $items = array();
129 if (class_exists('Forminator_API')) {
130 $forms = Forminator_API::get_forms(null, 1, 99999);
131 foreach ($forms as $key => $form) {
132 $items[] = $this->item($form->id);
133 }
134 }
135 return $items;
136 }
137
138 // datasets
139 public function datasets($item_id = false, $name = false) {
140 $datasets = array();
141 if (class_exists('Forminator_API') && $item_id) {
142 $entries = Forminator_API::get_entries($item_id);
143 $this->set('item', $item_id);
144 foreach ($entries as $key => $entry) {
145 $this->set('dataset', $entry->entry_id);
146 $entry_title = $this->render($name);
147 if (!$entry_title) {
148 $entry_title = $entry->entry_id;
149 }
150 $datasets[] = array(
151 'key' => $entry->entry_id,
152 'value' => $entry_title,
153 );
154 }
155 }
156 return $datasets;
157 }
158
159 // get dataset actions
160 public function get_dataset_actions($dataset_id = false) {
161 $dataset_id = (int) $dataset_id;
162 if (!$dataset_id) {
163 return false;
164 }
165 $actions = new stdClass();
166 $actions->view = false;
167 $actions->delete = false;
168 return $actions;
169 }
170
171 // get template actions
172 public function get_template_actions($template = false) {
173 $template = (int) $template;
174 if (!$template) {
175 return;
176 }
177 $actions = new stdClass();
178 $actions->delete = false;
179 return $actions;
180 }
181
182 // item
183 public function item($item_id = false) {
184 if (!$item_id && $this->get('item')) {
185 $item_id = $this->get('item');
186 }
187 $form = false;
188 if (class_exists('Forminator_API')) {
189 $form = Forminator_API::get_form($item_id);
190 }
191 $item = new stdClass();
192 if ($form && !is_wp_error($form)) {
193 $item->id = (string) $item_id;
194 $item->url = $this->helper->get_url(
195 array(
196 'page' => 'forminator-cform-wizard',
197 'id' => $form->id,
198 )
199 );
200 $item->name = function_exists('forminator_get_form_name') ? forminator_get_form_name($item_id, 'custom_form') : $form->name;
201 } else {
202 $item->id = '';
203 $item->url = '';
204 $item->name = '';
205 }
206 return $item;
207 }
208
209 // render
210 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
211 $value = $this->render_shortcodes($value, $field);
212 if (!$raw) {
213 $value = $this->strip_shortcodes($value);
214 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
215 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
216 }
217 return $value;
218 }
219
220 // render shortcodes
221 public function render_shortcodes($value, $field = array()) {
222 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
223 if ($this->verify() && function_exists('forminator_replace_form_data')) {
224 if ($this->get('cached_entry')) {
225 $cached_data = apply_filters('e2pdf_extension_render_forminator_data', $this->get('cached_data'), $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'));
226 $value = $this->replace_foreach($value, $this->get('cached_form'), $this->get('cached_entry'), $cached_data);
227 }
228 if (false !== strpos($value, '[')) {
229 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
230 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
231 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
232 }
233 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
234 if ($this->get('cached_entry')) {
235 if (defined('FORMINATOR_VERSION') && version_compare(FORMINATOR_VERSION, '1.16.0', '>=')) {
236 $prepared_data = Forminator_CForm_Front_Action::$prepared_data;
237 Forminator_CForm_Front_Action::$prepared_data = $cached_data;
238 $value = $this->forminator_replace_form_data($value, $this->get('cached_form'), $this->get('cached_entry'));
239 $value = forminator_replace_form_data($value, $this->get('cached_form'), $this->get('cached_entry'));
240 if (version_compare(FORMINATOR_VERSION, '1.17.2', '>=')) {
241 $value = forminator_replace_variables($value, $this->get('item'), $this->get('cached_entry'));
242 } else {
243 $value = forminator_replace_variables($value, $this->get('item'));
244 }
245 if (function_exists('forminator_replace_custom_form_data')) {
246 $value = forminator_replace_custom_form_data($value, $this->get('cached_form'), $this->get('cached_entry'));
247 }
248 Forminator_CForm_Front_Action::$prepared_data = $prepared_data;
249 } else {
250 $value = forminator_replace_form_data($value, $cached_data, $this->get('cached_form'), $this->get('cached_entry'));
251 $value = forminator_replace_variables($value, $this->get('item'));
252 if (function_exists('forminator_replace_custom_form_data')) {
253 $value = forminator_replace_custom_form_data($value, $this->get('cached_form'), $cached_data, $this->get('cached_entry'), array());
254 }
255 }
256 }
257 $value = $this->helper->load('field')->render(
258 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
259 $this,
260 $field
261 );
262 }
263 return apply_filters(
264 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
265 );
266 }
267
268 // replace foreach
269 public function replace_foreach($content, $custom_form = null, $entry = null, $data = array()) {
270
271 if (strpos($content, '{foreach:') !== false && preg_match_all('/\{foreach:(group-\d+)\}(.*?)\{\/foreach:(group-\d+)\}/s', $content, $matches)) {
272
273 $suffix_time = array('hours', 'minutes', 'ampm');
274 $suffix_address = array('street_address', 'address_line', 'city', 'state', 'zip', 'country');
275 $suffix_name = array('prefix', 'first-name', 'middle-name', 'last-name');
276
277 if (isset($matches[0]) && is_array($matches[0])) {
278 foreach ($matches[0] as $key => $match) {
279
280 $group_id = isset($matches[1][$key]) ? $matches[1][$key] : '';
281 $inner = isset($matches[2][$key]) ? $matches[2][$key] : '';
282 $outer = '';
283
284 if ($group_id) {
285 $group_fields = $custom_form->get_grouped_fields($group_id);
286 $original_keys = wp_list_pluck($group_fields, 'slug');
287 $repeater_keys = forminator_get_cloned_field_keys($entry, $original_keys);
288
289 $num_entries = 0;
290 if (count($repeater_keys) > 0) {
291 $num_entries = count($repeater_keys) + 1;
292 } else {
293 foreach ($original_keys as $original_key) {
294 if (stripos($original_key, 'address') !== false) {
295 foreach ($suffix_address as $sub_suffix) {
296 if (isset($data[$original_key . '-' . $sub_suffix]) && $data[$original_key . '-' . $sub_suffix]) {
297 $num_entries = 1;
298 break;
299 }
300 }
301 } elseif (stripos($original_key, 'time') !== false) {
302 foreach ($suffix_time as $sub_suffix) {
303 if (isset($data[$original_key . '-' . $sub_suffix]) && $data[$original_key . '-' . $sub_suffix]) {
304 $num_entries = 1;
305 break;
306 }
307 }
308 } elseif (stripos($original_key, 'name') !== false) {
309 foreach ($suffix_name as $sub_suffix) {
310 if (isset($data[$original_key . '-' . $sub_suffix]) && $data[$original_key . '-' . $sub_suffix]) {
311 $num_entries = 1;
312 break;
313 }
314 }
315 }
316
317 if (isset($data[$original_key])) {
318 $num_entries = 1;
319 }
320 if ($num_entries > 0) {
321 break;
322 }
323 }
324 }
325
326 $i = 1;
327 while ($i <= $num_entries) {
328 $replace = array();
329 foreach ($original_keys as $original_key) {
330 if (stripos($original_key, 'address') !== false) {
331 foreach ($suffix_address as $sub_suffix) {
332 $replace['{' . $original_key . '-' . $sub_suffix . '}'] = '{' . $original_key . '-' . $sub_suffix . ':' . $i . '}';
333 }
334 } elseif (stripos($original_key, 'time') !== false) {
335 foreach ($suffix_time as $sub_suffix) {
336 $replace['{' . $original_key . '-' . $sub_suffix . '}'] = '{' . $original_key . '-' . $sub_suffix . ':' . $i . '}';
337 }
338 } elseif (stripos($original_key, 'name') !== false) {
339 foreach ($suffix_name as $sub_suffix) {
340 $replace['{' . $original_key . '-' . $sub_suffix . '}'] = '{' . $original_key . '-' . $sub_suffix . ':' . $i . '}';
341 }
342 }
343 $replace['{' . $original_key . '}'] = '{' . $original_key . ':' . $i . '}';
344 $replace['{foreach-index}'] = $i;
345 }
346
347 $outer .= str_replace(array_keys($replace), $replace, $inner);
348 $i++;
349 }
350 $content = str_replace($match, $outer, $content);
351 }
352 }
353 }
354 }
355 return $content;
356 }
357
358 // replace form data
359 public function forminator_replace_form_data($content, $custom_form = null, $entry = null) {
360 $matches = array();
361 $data = Forminator_CForm_Front_Action::$prepared_data;
362 $field_types = Forminator_Core::get_field_types();
363 $suffix_time = array('hours', 'minutes', 'ampm');
364 $suffix_address = array('street_address', 'address_line', 'city', 'state', 'zip', 'country');
365 $randomed_field_pattern = 'field-\d+-\d+';
366 $increment_field_pattern = sprintf('(%s)-\d+', implode('|', $field_types));
367 if (preg_match_all('/\{((' . $randomed_field_pattern . ')|(' . $increment_field_pattern . '))(\-[A-Za-z-_]+)?(:\d+)?(:html)?\}/', $content, $matches)) {
368 if (!isset($matches[0]) || !is_array($matches[0])) {
369 return $content;
370 }
371 foreach ($matches[0] as $key => $match) {
372 $element_id = forminator_clear_field_id($match);
373
374 $suffix = isset($matches[5][$key]) ? $matches[5][$key] : null;
375 $index = isset($matches[6][$key]) ? str_replace(':', '', $matches[6][$key]) : null;
376 $filter = isset($matches[7][$key]) ? str_replace(':', '', $matches[7][$key]) : null;
377
378 if ($index) {
379 $field_id = isset($matches[1][$key]) ? $matches[1][$key] : null;
380 if (stripos($field_id, 'html') !== false) {
381 $content = str_replace($match, '{' . $field_id . '}', $content);
382 continue;
383 } else {
384 $field = $custom_form->get_field($field_id);
385 if ($field && isset($field['parent_group'])) {
386 $group_fields = $custom_form->get_grouped_fields($field['parent_group']);
387 $original_keys = wp_list_pluck($group_fields, 'slug');
388 $repeater_keys = array_values(forminator_get_cloned_field_keys($entry, $original_keys));
389
390 if ($index && $index >= '2') {
391 if (isset($repeater_keys[$index - 2])) {
392 $element_id = $field_id . $repeater_keys[$index - 2] . $suffix;
393 } else {
394 continue;
395 }
396 } else {
397 $element_id = $field_id . $suffix;
398 }
399 }
400 }
401 } elseif ($filter && $filter == 'html') {
402 $field_id = isset($matches[1][$key]) ? $matches[1][$key] : null;
403 $content = str_replace($match, forminator_replace_form_data('{' . $field_id . '}', $custom_form, $entry), $content);
404 continue;
405 }
406
407 if (isset($data[$element_id])) {
408 if (stripos($element_id, 'currency') !== false || stripos($element_id, 'number') !== false) {
409 $field = $custom_form->get_field($element_id, true);
410 $value = Forminator_Field::forminator_number_formatting($field, $data[$element_id]);
411 } elseif (
412 false !== stripos($element_id, 'time') &&
413 (false !== stripos($element_id, '-hours') || false !== stripos($element_id, '-minutes'))
414 ) {
415 $value = str_pad($data[$element_id], 2, '0', STR_PAD_LEFT);
416 } elseif (!empty($entry->draft_id) &&
417 function_exists('forminator_replace_field_data') &&
418 (strpos($element_id, 'radio') === 0 || strpos($element_id, 'select') === 0 || strpos($element_id, 'checkbox') === 0)
419 ) {
420 $value = explode(', ', forminator_replace_field_data($custom_form, $element_id, $data));
421 } else {
422 $value = $data[$element_id];
423 }
424 if (is_array($value)) {
425 $value = implode(', ', $value);
426 }
427 $content = str_replace($match, $value, $content);
428 } elseif (stripos($element_id, 'calculation') !== false && $custom_form && $entry) {
429 if ($index) {
430 // incorrect value for repeater with default function
431 $value = render_entry($entry, $element_id);
432 } else {
433 $value = forminator_get_field_from_form_entry($element_id, $custom_form, $entry);
434 }
435
436 if (is_array($value)) {
437 $value = implode(', ', $value);
438 }
439 $content = str_replace($match, $value, $content);
440 } elseif (stripos($element_id, 'address') !== false && !$suffix) {
441
442 $address = array();
443 foreach ($suffix_address as $sub_suffix) {
444 if (isset($data[$element_id . '-' . $sub_suffix]) && $data[$element_id . '-' . $sub_suffix]) {
445 $address[$sub_suffix] = $data[$element_id . '-' . $sub_suffix];
446 }
447 }
448
449 $value = apply_filters('e2pdf_extension_forminator_replace_form_data_address', implode(', ', $address), $element_id, $address, $custom_form, $entry);
450 $content = str_replace($match, $value, $content);
451 } elseif (stripos($element_id, 'time') !== false && !$suffix) {
452 $time = array();
453 foreach ($suffix_time as $sub_suffix) {
454 if (isset($data[$element_id . '-' . $sub_suffix])) {
455 if ($sub_suffix == 'hours' || $sub_suffix == 'minutes') {
456 $time[$sub_suffix] = str_pad($data[$element_id . '-' . $sub_suffix], 2, '0', STR_PAD_LEFT);
457 } else {
458 $time[$sub_suffix] = $data[$element_id . '-' . $sub_suffix];
459 }
460 }
461 }
462 $value = apply_filters('e2pdf_extension_forminator_replace_form_data_time', implode(':', $time), $element_id, $time, $custom_form, $entry);
463 $content = str_replace($match, $value, $content);
464 } elseif (false !== stripos($element_id, 'postdata') && $suffix) {
465 $field_id = isset($matches[1][$key]) ? $matches[1][$key] : null;
466 $meta_value = isset($data[$field_id . '-value']) ? $data[$field_id . '-value'] : array();
467
468 switch ($suffix) {
469 case '-post-title':
470 $value = isset($meta_value['post-title']) ? $meta_value['post-title'] : '';
471 $content = str_replace($match, $value, $content);
472 break;
473 case '-post-content':
474 $value = isset($meta_value['post-content']) ? $meta_value['post-content'] : '';
475 $content = str_replace($match, $value, $content);
476 break;
477 case '-post-excerpt':
478 $value = isset($meta_value['post-excerpt']) ? $meta_value['post-excerpt'] : '';
479 $content = str_replace($match, $value, $content);
480 break;
481 case '-category':
482 $post_category = isset($meta_value['category']) ? $meta_value['category'] : '';
483 $categories = array();
484 if (is_array($post_category)) {
485 foreach ($post_category as $category) {
486 $categories[] = get_the_category_by_ID($category);
487 }
488 } elseif ($post_category) {
489 $categories[] = get_the_category_by_ID($post_category);
490 }
491 $value = implode(', ', $categories);
492 $content = str_replace($match, $value, $content);
493 break;
494 case '-post_tag':
495 $post_tags = isset($meta_value['post_tag']) ? $meta_value['post_tag'] : '';
496 $tags = array();
497 if (is_array($post_tags)) {
498 foreach ($post_tags as $post_tag) {
499 $term = get_term_by('id', $post_tag, 'post_tag');
500 if ($term) {
501 $tags[] = $term->name;
502 }
503 }
504 } elseif ($post_tags) {
505 $term = get_term_by('id', $post_tag, 'post_tag');
506 if ($term) {
507 $tags[] = $term->name;
508 }
509 }
510 $value = implode(', ', $tags);
511 $content = str_replace($match, $value, $content);
512 break;
513 case '-post-custom':
514 $post_custom = isset($meta_value['post-custom']) && is_array($meta_value['post-custom']) ? $meta_value['post-custom'] : array();
515 $customs = array();
516 foreach ($post_custom as $custom) {
517 $customs[] = $custom['key'] . ': ' . $custom['value'];
518 }
519 $value = implode(', ', $customs);
520 $content = str_replace($match, $value, $content);
521 break;
522 case '-post-image':
523 $value = !empty($meta_value['post-image']) && !empty($meta_value['post-image']['uploaded_file']) ? $meta_value['post-image']['uploaded_file'][0] : '';
524 $content = str_replace($match, $value, $content);
525 break;
526 }
527 }
528 }
529 }
530 return $content;
531 }
532
533 // Fix: Compatibility with Forminator 1.48.x
534 public function update_meta_data($meta_data) {
535 foreach ($meta_data as $meta_key => $meta) {
536 if ((false !== strpos($meta_key, 'checkbox') || false !== strpos($meta_key, 'select')) && !empty($meta['value']) && is_string($meta['value'])) {
537 $meta_data[$meta_key]['value'] = implode(', ', explode('<br/>', $meta['value']));
538 }
539 }
540 return $meta_data;
541 }
542
543 // replace values to labels
544 public function replace_values_to_labels($data, $form, $entry) {
545 if (function_exists('forminator_replace_form_data')) {
546 foreach ($data as $key => $value) {
547 if (empty($value['name'])) {
548 continue;
549 }
550 $slug = $value['name'];
551 if (strpos($slug, 'radio') !== false || strpos($slug, 'select') !== false || strpos($slug, 'checkbox') !== false
552 ) {
553 $data[$key]['value'] = forminator_replace_form_data('{' . $slug . '}', $form, $entry, true);
554 }
555 }
556 }
557 return $data;
558 }
559
560 // strip shortcodes
561 public function strip_shortcodes($value) {
562 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
563 $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value);
564 return $value;
565 }
566
567 // strip math
568 public function strip_math($value, &$replacements) {
569 if ($value) {
570 preg_match_all('/\{[^}]+\}/', $value, $matches);
571 foreach ($matches[0] as $match) {
572 $index = count($replacements) + 1;
573 $replacements[] = $match;
574 $value = str_replace($match, '%' . $index . '$s', $value);
575 }
576 }
577 return $value;
578 }
579
580 // convert shortcodes
581 public function convert_shortcodes($value, $to = false, $html = false) {
582 if ($value) {
583 if ($to) {
584 $value = str_replace('&#91;', '[', $value);
585 if (!$html) {
586 $value = wp_specialchars_decode($value, ENT_QUOTES);
587 }
588 } else {
589 $value = str_replace('[', '&#91;', $value);
590 }
591 }
592 return $value;
593 }
594
595 // verify
596 public function verify() {
597 if ($this->get('cached_form')) {
598 if (
599 ($this->get('cached_form')->is_prevent_store() && $this->get('dataset') == 'is_prevent_store') ||
600 ($this->get('cached_entry') && $this->get('cached_entry')->form_id == $this->get('item'))
601 ) {
602 return true;
603 }
604 }
605 return false;
606 }
607
608 // auto form
609 public function auto_form($template, $data = array()) {
610
611 if ($template->get('ID')) {
612
613 $auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false;
614 $auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false;
615 $wrappers = array();
616 $pages = $template->get('pages');
617 $checkboxes = array();
618 $radios = array();
619
620 foreach ($pages as $page_key => $page) {
621 if (isset($page['elements']) && !empty($page['elements'])) {
622 foreach ($page['elements'] as $element_key => $element) {
623 $type = false;
624 $label = '';
625 if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') {
626 $type = 'text';
627 $label = 'Text';
628 } elseif ($element['type'] == 'e2pdf-textarea') {
629 $type = 'textarea';
630 $label = 'Textarea';
631 } elseif ($element['type'] == 'e2pdf-select') {
632 $type = 'select';
633 $label = 'Select';
634 $options = array();
635 $field_options = array();
636 if (isset($element['properties']['options'])) {
637 $field_options = explode("\n", $element['properties']['options']);
638 foreach ($field_options as $option) {
639 $options[] = array(
640 'label' => $option,
641 'value' => '',
642 );
643 }
644 }
645 } elseif ($element['type'] == 'e2pdf-checkbox') {
646 $field_key = array_search($element['name'], array_column($checkboxes, 'name'), false);
647 if ($field_key !== false) {
648 $checkboxes[$field_key]['options'][] = array(
649 'label' => $element['properties']['option'],
650 'value' => $element['properties']['option'],
651 );
652 $pages[$page_key]['elements'][$element_key]['value'] = '{checkbox-' . $checkboxes[$field_key]['element_id'] . '}';
653 } else {
654 $type = 'checkbox';
655 $label = 'Checkbox';
656 $options = array(
657 'label' => $element['properties']['option'],
658 'value' => $element['properties']['option'],
659 );
660 }
661 } elseif ($element['type'] == 'e2pdf-radio') {
662 if (isset($element['properties']['group']) && $element['properties']['group']) {
663 $element['name'] = $element['properties']['group'];
664 } else {
665 $element['name'] = $element['element_id'];
666 }
667 $field_key = array_search($element['name'], array_column($radios, 'name'), false);
668 if ($field_key !== false) {
669 $radios[$field_key]['options'][] = array(
670 'label' => $element['properties']['option'],
671 'value' => '',
672 );
673 $pages[$page_key]['elements'][$element_key]['value'] = '{radio-' . $radios[$field_key]['element_id'] . '}';
674 } else {
675 $type = 'radio';
676 $label = 'Radio';
677 $options = array(
678 'label' => $element['properties']['option'],
679 'value' => '',
680 );
681 }
682 }
683
684 if ($type) {
685 $labels = array();
686 if ($auto_form_shortcode) {
687 $labels[] = '{' . $type . '-' . $element['element_id'] . '}';
688 }
689
690 if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) {
691 $labels[] = $element['value'];
692 } elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) {
693 $labels[] = $element['name'];
694 }
695
696 if ($type == 'checkbox' || $type == 'radio') {
697
698 $field_data = array(
699 'name' => $element['name'],
700 'element_id' => $element['element_id'],
701 'field_label' => !empty($labels) ? implode(' ', $labels) : $label,
702 'options' => array(
703 $options,
704 ),
705 );
706
707 if ($type == 'checkbox') {
708 $checkboxes[] = $field_data;
709 } else {
710 $radios[] = $field_data;
711 }
712 } else {
713 $field_data = array(
714 'element_id' => $type . '-' . $element['element_id'],
715 'type' => $type,
716 'cols' => '12',
717 'required' => false,
718 'field_label' => !empty($labels) ? implode(' ', $labels) : $label,
719 'placeholder' => '',
720 'validation' => false,
721 );
722
723 if ($type == 'select') {
724 $field_data['options'] = $options;
725 }
726
727 $wrappers[] = array(
728 'wrapper_id' => 'wrapper-' . wp_rand(1000000000000, 9999999999999) . '-' . wp_rand(1000, 9999),
729 'fields' => array(
730 $field_data,
731 ),
732 );
733 }
734
735 $pages[$page_key]['elements'][$element_key]['value'] = '{' . $type . '-' . $element['element_id'] . '}';
736 if (isset($element['properties']['esig'])) {
737 unset($pages[$page_key]['elements'][$element_key]['properties']['esig']);
738 }
739 }
740 }
741 }
742 }
743
744 foreach ($checkboxes as $element) {
745 $wrappers[] = array(
746 'wrapper_id' => 'wrapper-' . wp_rand(1000000000000, 9999999999999) . '-' . wp_rand(1000, 9999),
747 'fields' => array(
748 array(
749 'element_id' => 'checkbox-' . $element['element_id'],
750 'type' => 'checkbox',
751 'cols' => '12',
752 'required' => false,
753 'options' => $element['options'],
754 'field_label' => $element['field_label'],
755 'placeholder' => '',
756 'validation' => false,
757 ),
758 ),
759 );
760 }
761
762 foreach ($radios as $element) {
763 $wrappers[] = array(
764 'wrapper_id' => 'wrapper-' . wp_rand(1000000000000, 9999999999999) . '-' . wp_rand(1000, 9999),
765 'fields' => array(
766 array(
767 'element_id' => 'radio-' . $element['element_id'],
768 'type' => 'radio',
769 'cols' => '12',
770 'required' => false,
771 'options' => $element['options'],
772 'field_label' => $element['field_label'],
773 'placeholder' => '',
774 'validation' => false,
775 ),
776 ),
777 );
778 }
779
780 $template->set('pages', $pages);
781 $settings = array(
782 'formName' => $template->get('title'),
783 'thankyou' => 'true',
784 /* translators: %d: E2Pdf Template ID */
785 'thankyou-message' => sprintf(__('Success. [e2pdf-download id="%d"]', 'e2pdf'), $template->get('ID')),
786 'use-custom-submit' => 'true',
787 'custom-submit-text' => __('Send Message', 'forminator'),
788 'use-custom-invalid-form' => 'true',
789 'custom-invalid-form-message' => __('Error: Your form is not valid, please fix the errors!', 'forminator'),
790 'enable-ajax' => 'true',
791 'validation' => 'on_submit',
792 );
793
794 if (class_exists('Forminator_API')) {
795 $item = Forminator_API::add_form($template->get('title'), $wrappers, $settings);
796 if ($item) {
797 $template->set('item', $item);
798 }
799 }
800 }
801
802 return $template;
803 }
804
805 // visual mapper
806 public function visual_mapper() {
807
808 $item = $this->get('item');
809 $html = '';
810 $source = '';
811
812 if ($item && class_exists('Forminator_API') && class_exists('Forminator_CForm_Front')) {
813 $custom_form = Forminator_API::get_form($item);
814 if (is_wp_error($custom_form)) {
815 return __('Form could not be found', 'e2pdf');
816 }
817 $view = Forminator_CForm_Front::get_instance();
818 if (class_exists('Forminator_Custom_Form_Model')) {
819 $view->model = Forminator_Custom_Form_Model::model()->load($item);
820 } elseif (class_exists('Forminator_Form_Model')) {
821 $view->model = Forminator_Form_Model::model()->load($item);
822 } else {
823 return __('Something went wrong!', 'e2pdf');
824 }
825
826 $fields = $view->get_fields();
827 if (!empty($fields)) {
828 foreach ($fields as $field_key => $field) {
829 if ('page-break' === $field['type'] && isset($field['element_id'])) {
830 $view->model->remove_field($field_key);
831 }
832 }
833 }
834
835 $form = $view->get_html(true, true);
836 ob_start();
837 $view->print_styles();
838 $styles = ob_get_clean();
839 if ($form) {
840 $source = $styles . $form;
841 }
842 if ($source) {
843 $dom = new DOMDocument();
844 $html = $this->helper->load('convert')->load_html($source, $dom, true);
845 }
846 if (!$source) {
847 return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
848 } elseif (!$html) {
849 return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
850 } else {
851
852 $use_labels = true;
853 if ((defined('FORMINATOR_VERSION') && version_compare(FORMINATOR_VERSION, '1.14.10', '<')) || (!empty($custom_form->settings['print_value']) && filter_var($custom_form->settings['print_value'], FILTER_VALIDATE_BOOLEAN))) {
854 $use_labels = false;
855 }
856
857 $xml = $this->helper->load('xml');
858 $xpath = new DomXPath($dom);
859
860 // remove by class
861 $remove_by_class = array(
862 'forminator-pagination-submit',
863 'forminator-response-message',
864 'forminator-save-draft-link',
865 'forminator-field-stripe',
866 'forminator-button-paypal',
867 );
868 foreach ($remove_by_class as $key => $class) {
869 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
870 foreach ($elements as $element) {
871 $element->parentNode->removeChild($element);
872 }
873 }
874
875 // remove by tag
876 $remove_by_tag = array(
877 'script',
878 );
879 foreach ($remove_by_tag as $key => $tag) {
880 $elements = $xpath->query('//' . $tag);
881 foreach ($elements as $element) {
882 $element->parentNode->removeChild($element);
883 }
884 }
885
886 $inputs = $xpath->query("//*[contains(@class, 'forminator-input') or contains(@class, 'forminator-calculation')]");
887 foreach ($inputs as $element) {
888 $xml->set_node_value($element, 'type', 'text');
889 }
890
891 // remove pagination
892 $pagination = $xpath->query("//*[contains(@class, 'forminator-pagination')]");
893 foreach ($pagination as $element) {
894 $xml->set_node_value($element, 'style', '');
895 }
896
897 // remove buttons
898 $remove_rows = $xpath->query("//*[contains(@class, 'forminator-row')][.//button[contains(concat(' ',@class,' '), ' forminator-button ') and not(contains(@class, 'forminator-upload-button')) and not(contains(@class, 'forminator-button-upload'))]]");
899 foreach ($remove_rows as $element) {
900 $element->parentNode->removeChild($element);
901 }
902
903 // sliders support
904 $sliders = $xpath->query("//*[contains(@class, 'forminator-slider-hidden-min') or contains(@class, 'forminator-slider-hidden-max')]");
905 foreach ($sliders as $element) {
906 $xml->set_node_value($element, 'type', 'text');
907 }
908
909 // replace name on fileuploads
910 $fileuploads = $xpath->query("//*[contains(@class, 'forminator-upload')]");
911 foreach ($fileuploads as $element) {
912 $file = $xpath->query(".//input[contains(@class, 'forminator-input-file')]", $element)->item(0);
913 $button = $xpath->query(".//button[contains(@class, 'forminator-upload-button') or contains(@class, 'forminator-button-upload')]", $element)->item(0);
914 if ($file && $button) {
915 $xml->set_node_value($button, 'type', 'upload');
916 $xml->set_node_value($button, 'name', $xml->get_node_value($file, 'name'));
917 }
918 }
919
920 // replace name on multi-fileuploads
921 $fileuploads_multi = $xpath->query("//*[contains(@class, 'forminator-multi-upload')]");
922 foreach ($fileuploads_multi as $element) {
923 $file = $xpath->query(".//input[contains(@class, 'forminator-input-file')]", $element)->item(0);
924 if ($file) {
925 $xml->set_node_value($file, 'name', str_replace('[]', '', $xml->get_node_value($file, 'name')));
926 }
927 }
928
929 // replace name on signatures
930 $signatures = $xpath->query("//*[contains(@class, 'forminator-field-signature')]");
931 foreach ($signatures as $element) {
932 $button = $xpath->query(".//input[contains(@type, 'hidden')]", $element)->item(0);
933 if ($button) {
934 $xml->set_node_value($button, 'type', 'text');
935 $xml->set_node_value($button, 'value', '');
936 $xml->set_node_value($button, 'name', str_replace('field-', '', $xml->get_node_value($button, 'name')));
937 }
938 }
939
940 // replace names on inputs
941 $inputs = $xpath->query('//input|//textarea|//select');
942 foreach ($inputs as $element) {
943 if ($xml->get_node_value($element, 'type') == 'checkbox') {
944 $xml->set_node_value($element, 'name', str_replace('[]', '', $xml->get_node_value($element, 'name')));
945 /* Forminator 1.14.10 Checkbox "Option" Fix */
946 if ($use_labels) {
947 $parent = $xpath->query('.//parent::*', $element);
948 if ($parent && $parent->item(0)) {
949 if (strpos($xml->get_node_value($parent->item(0), 'class'), 'forminator-option') !== false) {
950 $xml->set_node_value($element, 'value', $parent->item(0)->nodeValue);
951 } else {
952 $label = $xpath->query('.//parent::*/span[not(@aria-hidden)]', $element);
953 if ($label && $label->item(0)) {
954 $xml->set_node_value($element, 'value', $label->item(0)->nodeValue);
955 }
956 }
957 }
958 }
959 }
960
961 if ($use_labels) {
962 // forminator 1.14.10 radio option fix
963 if ($xml->get_node_value($element, 'type') == 'radio') {
964 $label = $xpath->query('.//parent::*/span[not(@aria-hidden)]', $element);
965 if ($label && $label->item(0)) {
966 $xml->set_node_value($element, 'value', $label->item(0)->nodeValue);
967 }
968 }
969
970 // forminator 1.14.10 select option fix
971 if ($element->tagName == 'select') {
972 $options = $xpath->query('.//option', $element);
973 if ($options) {
974 foreach ($options as $option) {
975 $xml->set_node_value($option, 'value', $option->nodeValue);
976 }
977 }
978 }
979 }
980
981 $parent_repeater = $xpath->query("./ancestor::div[contains(@class, 'forminator-repeater-field')]", $element);
982 if ($parent_repeater && $parent_repeater->item(0)) {
983 $xml->set_node_value($element, 'name', $xml->get_node_value($element, 'name') . ':1');
984 }
985
986 $xml->set_node_value($element, 'name', '{' . $xml->get_node_value($element, 'name') . '}');
987
988 if (strpos($xml->get_node_value($element, 'class'), 'forminator-checkbox--input') !== false) {
989 $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' forminator-checkbox--design');
990 }
991 if (strpos($xml->get_node_value($element, 'class'), 'forminator-radio--input') !== false) {
992 $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' forminator-radio--design');
993 }
994 }
995
996 // multiselects
997 $multiselect = $xpath->query("//ul[contains(@class, 'forminator-multiselect')]");
998 foreach ($multiselect as $element) {
999 $name = '';
1000 $options = array();
1001 $inputs = $xpath->query(".//*[contains(@class, 'forminator-multiselect--item')]", $element);
1002
1003 foreach ($inputs as $sub_element) {
1004 $input = $xpath->query('.//input', $sub_element)->item(0);
1005 $label = $xpath->query('.//label', $sub_element)->item(0);
1006
1007 if ($input && $label) {
1008 if ($label->childNodes->item(0)) {
1009 $options[] = array(
1010 'value' => $xml->get_node_value($input, 'value'),
1011 'label' => $label->childNodes->item(0)->nodeValue,
1012 );
1013 }
1014 $name = $xml->get_node_value($input, 'name');
1015 }
1016 $sub_element->parentNode->removeChild($sub_element);
1017 }
1018
1019 $li = $dom->createElement('li');
1020 $field_atts = array(
1021 'class' => 'forminator-multiselect--item',
1022 );
1023 foreach ($field_atts as $key => $value) {
1024 $attr = $dom->createAttribute($key);
1025 $attr->value = $value;
1026 $li->appendChild($attr);
1027 }
1028 $element->appendChild($li);
1029
1030 $field = $dom->createElement('select');
1031 $field_atts = array(
1032 'multiple' => 'multiple',
1033 'name' => $name,
1034 );
1035 foreach ($field_atts as $key => $value) {
1036 $attr = $dom->createAttribute($key);
1037 $attr->value = $value;
1038 $field->appendChild($attr);
1039 }
1040
1041 $li->appendChild($field);
1042
1043 foreach ($options as $option) {
1044 $option_field = $dom->createElement('option');
1045 $field_atts = array(
1046 'value' => $option['value'],
1047 );
1048 foreach ($field_atts as $key => $value) {
1049 $attr = $dom->createAttribute($key);
1050 $attr->value = $value;
1051 $option_field->appendChild($attr);
1052 }
1053
1054 $label = $dom->createTextNode($option['label']);
1055 $option_field->appendChild($label);
1056 $field->appendChild($option_field);
1057 }
1058 }
1059
1060 // replace hidden
1061 $elements = $xpath->query("//*[contains(@type, 'hidden')]");
1062 foreach ($elements as $element) {
1063 $parent = $xpath->query('.//parent::*', $element);
1064 if ($parent && $parent->item(0)) {
1065 if (false !== strpos($xml->get_node_value($parent->item(0), 'class'), 'forminator-row')) {
1066 if (false !== strpos($xml->get_node_value($parent->item(0), 'class'), 'forminator-hidden')) {
1067 $xml->set_node_value($element, 'value', $xml->get_node_value($element, 'name'));
1068 }
1069 $xml->set_node_value($parent->item(0), 'class', 'forminator-field');
1070 } else {
1071 $element->parentNode->removeChild($element);
1072 }
1073 }
1074 }
1075
1076 $elements = $xpath->query("//*[contains(@class, 'forminator-row') and not(.//text()[normalize-space()])]");
1077 foreach ($elements as $element) {
1078 $element->parentNode->removeChild($element);
1079 }
1080
1081 return $dom->saveHTML();
1082 }
1083 }
1084 return false;
1085 }
1086
1087 // auto
1088 public function auto() {
1089
1090 $item = $this->get('item');
1091
1092 $response = array();
1093 $elements = array();
1094 $form_fields = array();
1095 $custom_form = false;
1096
1097 if (class_exists('Forminator_API')) {
1098 $custom_form = Forminator_API::get_form($item);
1099 if (!is_wp_error($custom_form)) {
1100 $form_fields = $custom_form->fields;
1101 }
1102 }
1103
1104 if ($custom_form && !empty($form_fields)) {
1105 $fields = array();
1106 foreach ($form_fields as $field_obj) {
1107 $field = $field_obj->raw;
1108 if (isset($field['type']) && $field['type'] == 'group') {
1109 $fields[] = $field_obj;
1110 if (isset($field['element_id']) && $field['element_id']) {
1111 foreach ($form_fields as $sub_field_obj) {
1112 if (isset($sub_field_obj->parent_group) && $sub_field_obj->parent_group == $field['element_id']) {
1113 $fields[] = $sub_field_obj;
1114 }
1115 }
1116 }
1117 } elseif (isset($field_obj->parent_group) && $field_obj->parent_group) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElseif
1118 } else {
1119 $fields[] = $field_obj;
1120 }
1121 }
1122
1123 $use_labels = true;
1124 if ((defined('FORMINATOR_VERSION') && version_compare(FORMINATOR_VERSION, '1.14.10', '<')) || (!empty($custom_form->settings['print_value']) && filter_var($custom_form->settings['print_value'], FILTER_VALIDATE_BOOLEAN))) {
1125 $use_labels = false;
1126 }
1127
1128 foreach ($fields as $field_obj) {
1129 $field = $field_obj->raw;
1130 $width = 100 / (12 / $field['cols']);
1131 $repeater = '';
1132 if (isset($field_obj->parent_group) && $field_obj->parent_group) {
1133 $parent_field = $custom_form->get_field($field_obj->parent_group);
1134 if ($parent_field) {
1135 if (isset($parent_field['is_repeater']) && $parent_field['is_repeater']) {
1136 $repeater = ':1';
1137 }
1138 }
1139 }
1140
1141 switch ($field['type']) {
1142 case 'group':
1143 if ($field['field_label']) {
1144 $elements[] = $this->auto_field(
1145 $field,
1146 array(
1147 'type' => 'e2pdf-html',
1148 'block' => true,
1149 'properties' => array(
1150 'top' => '20',
1151 'left' => '20',
1152 'right' => '20',
1153 'width' => $width . '%',
1154 'height' => 'auto',
1155 'value' => '<h2>' . $field['field_label'] . '</h2>',
1156 ),
1157 )
1158 );
1159 }
1160 break;
1161 case 'name':
1162 case 'email':
1163 case 'phone':
1164 case 'url':
1165 case 'number':
1166 case 'calculation':
1167 case 'date':
1168 case 'currency':
1169 // multiple name field
1170 if ($field['type'] == 'name' && isset($field['multiple_name']) && $field['multiple_name'] === 'true') {
1171
1172 if (!$field['prefix'] && !$field['fname']) {
1173 if ($field['mname']) {
1174 $elements[] = $this->auto_field(
1175 $field,
1176 array(
1177 'type' => 'e2pdf-html',
1178 'block' => true,
1179 'float' => true,
1180 'properties' => array(
1181 'top' => '20',
1182 'left' => '20',
1183 'right' => '20',
1184 'width' => $field['lname'] ? $width / 2 . '%' : $width . '%',
1185 'height' => 'auto',
1186 'value' => $field['mname_label'],
1187 ),
1188 )
1189 );
1190
1191 $elements[] = $this->auto_field(
1192 $field,
1193 array(
1194 'type' => 'e2pdf-input',
1195 'properties' => array(
1196 'top' => '5',
1197 'width' => '100%',
1198 'height' => 'auto',
1199 'value' => '{' . $field['element_id'] . '-middle-name' . $repeater . '}',
1200 ),
1201 )
1202 );
1203 }
1204
1205 if ($field['lname']) {
1206 $elements[] = $this->auto_field(
1207 $field,
1208 array(
1209 'type' => 'e2pdf-html',
1210 'block' => true,
1211 'float' => true,
1212 'properties' => array(
1213 'top' => '20',
1214 'left' => '20',
1215 'right' => '20',
1216 'width' => $field['mname'] ? $width / 2 . '%' : $width . '%',
1217 'height' => 'auto',
1218 'value' => $field['lname_label'],
1219 ),
1220 )
1221 );
1222
1223 $elements[] = $this->auto_field(
1224 $field,
1225 array(
1226 'type' => 'e2pdf-input',
1227 'properties' => array(
1228 'top' => '5',
1229 'width' => '100%',
1230 'height' => 'auto',
1231 'value' => '{' . $field['element_id'] . '-last-name' . $repeater . '}',
1232 ),
1233 )
1234 );
1235 }
1236 } else {
1237 if ($field['prefix']) {
1238 $elements[] = $this->auto_field(
1239 $field,
1240 array(
1241 'type' => 'e2pdf-html',
1242 'block' => true,
1243 'float' => true,
1244 'properties' => array(
1245 'top' => '20',
1246 'left' => '20',
1247 'right' => '20',
1248 'width' => $field['fname'] ? $width / 2 . '%' : $width . '%',
1249 'height' => 'auto',
1250 'value' => $field['prefix_label'],
1251 ),
1252 )
1253 );
1254
1255 $options_tmp = array();
1256 if (function_exists('forminator_get_name_prefixes')) {
1257 $options = forminator_get_name_prefixes();
1258 foreach ($options as $key => $option) {
1259 $options_tmp[] = $key;
1260 }
1261 }
1262
1263 $elements[] = $this->auto_field(
1264 $field,
1265 array(
1266 'type' => 'e2pdf-select',
1267 'properties' => array(
1268 'top' => '5',
1269 'width' => '100%',
1270 'height' => 'auto',
1271 'options' => implode("\n", $options_tmp),
1272 'value' => '{' . $field['element_id'] . '-prefix' . $repeater . '}',
1273 ),
1274 )
1275 );
1276
1277 if ($field['mname'] && $field['fname']) {
1278 $elements[] = $this->auto_field(
1279 $field,
1280 array(
1281 'type' => 'e2pdf-html',
1282 'properties' => array(
1283 'top' => '20',
1284 'width' => $field['lname'] ? '100%' : '200%',
1285 'right' => $field['lname'] ? '0' : '-40',
1286 'height' => 'auto',
1287 'value' => $field['mname_label'],
1288 ),
1289 )
1290 );
1291
1292 $elements[] = $this->auto_field(
1293 $field,
1294 array(
1295 'type' => 'e2pdf-input',
1296 'properties' => array(
1297 'top' => '5',
1298 'width' => $field['lname'] ? '100%' : '200%',
1299 'height' => 'auto',
1300 'right' => $field['lname'] ? '0' : '-40',
1301 'value' => '{' . $field['element_id'] . '-middle-name' . $repeater . '}',
1302 ),
1303 )
1304 );
1305 } elseif ($field['lname'] && !$field['mname'] && $field['fname']) {
1306
1307 $elements[] = $this->auto_field(
1308 $field,
1309 array(
1310 'type' => 'e2pdf-html',
1311 'properties' => array(
1312 'top' => '20',
1313 'width' => $field['mname'] ? '100%' : '200%',
1314 'height' => 'auto',
1315 'right' => $field['mname'] ? '0' : '-40',
1316 'value' => $field['lname_label'],
1317 ),
1318 )
1319 );
1320
1321 $elements[] = $this->auto_field(
1322 $field,
1323 array(
1324 'type' => 'e2pdf-input',
1325 'properties' => array(
1326 'top' => '5',
1327 'width' => $field['mname'] ? '100%' : '200%',
1328 'height' => 'auto',
1329 'right' => $field['mname'] ? '0' : '-40',
1330 'value' => '{' . $field['element_id'] . '-last-name' . $repeater . '}',
1331 ),
1332 )
1333 );
1334 }
1335 }
1336
1337 if ($field['fname']) {
1338 $elements[] = $this->auto_field(
1339 $field,
1340 array(
1341 'type' => 'e2pdf-html',
1342 'block' => true,
1343 'float' => true,
1344 'properties' => array(
1345 'top' => '20',
1346 'left' => '20',
1347 'right' => '20',
1348 'width' => $field['prefix'] ? ($width / 2) . '%' : $width . '%',
1349 'height' => 'auto',
1350 'value' => $field['fname_label'],
1351 ),
1352 )
1353 );
1354
1355 $elements[] = $this->auto_field(
1356 $field,
1357 array(
1358 'type' => 'e2pdf-input',
1359 'properties' => array(
1360 'top' => '5',
1361 'width' => '100%',
1362 'height' => 'auto',
1363 'value' => '{' . $field['element_id'] . '-first-name' . $repeater . '}',
1364 ),
1365 )
1366 );
1367
1368 if ($field['lname'] && $field['mname'] && $field['prefix']) {
1369 $elements[] = $this->auto_field(
1370 $field,
1371 array(
1372 'type' => 'e2pdf-html',
1373 'properties' => array(
1374 'top' => '20',
1375 'width' => $field['mname'] ? '100%' : '200%',
1376 'height' => 'auto',
1377 'right' => $field['mname'] ? '0' : '-40',
1378 'value' => $field['lname_label'],
1379 ),
1380 )
1381 );
1382
1383 $elements[] = $this->auto_field(
1384 $field,
1385 array(
1386 'type' => 'e2pdf-input',
1387 'properties' => array(
1388 'top' => '5',
1389 'width' => $field['mname'] ? '100%' : '200%',
1390 'height' => 'auto',
1391 'right' => $field['mname'] ? '0' : '-40',
1392 'value' => '{' . $field['element_id'] . '-last-name' . $repeater . '}',
1393 ),
1394 )
1395 );
1396 }
1397 }
1398
1399 if (!$field['prefix'] || !$field['fname']) {
1400 if ($field['mname']) {
1401 $elements[] = $this->auto_field(
1402 $field,
1403 array(
1404 'type' => 'e2pdf-html',
1405 'properties' => array(
1406 'top' => '20',
1407 'right' => $field['lname'] ? '20' : '0',
1408 'width' => $field['lname'] ? '50%' : '100%',
1409 'height' => 'auto',
1410 'value' => $field['mname_label'],
1411 ),
1412 )
1413 );
1414 }
1415
1416 if ($field['lname']) {
1417 $elements[] = $this->auto_field(
1418 $field,
1419 array(
1420 'type' => 'e2pdf-html',
1421 'float' => $field['mname'] ? true : false,
1422 'properties' => array(
1423 'top' => '20',
1424 'left' => $field['mname'] ? '20' : '0',
1425 'width' => $field['mname'] ? '50%' : '100%',
1426 'height' => 'auto',
1427 'value' => $field['lname_label'],
1428 ),
1429 )
1430 );
1431 }
1432
1433 if ($field['mname']) {
1434 $elements[] = $this->auto_field(
1435 $field,
1436 array(
1437 'type' => 'e2pdf-input',
1438 'properties' => array(
1439 'top' => '5',
1440 'right' => $field['lname'] ? '20' : '0',
1441 'width' => $field['lname'] ? '50%' : '100%',
1442 'height' => 'auto',
1443 'value' => '{' . $field['element_id'] . '-middle-name' . $repeater . '}',
1444 ),
1445 )
1446 );
1447 }
1448
1449 if ($field['lname']) {
1450 $elements[] = $this->auto_field(
1451 $field,
1452 array(
1453 'type' => 'e2pdf-input',
1454 'float' => $field['mname'] ? true : false,
1455 'properties' => array(
1456 'top' => '5',
1457 'left' => $field['mname'] ? '20' : '0',
1458 'width' => $field['mname'] ? '50%' : '100%',
1459 'height' => 'auto',
1460 'value' => '{' . $field['element_id'] . '-last-name' . $repeater . '}',
1461 ),
1462 )
1463 );
1464 }
1465 }
1466 }
1467 } elseif ($field['type'] == 'date' && $field['field_type'] == 'select') {
1468
1469 $elements[] = $this->auto_field(
1470 $field,
1471 array(
1472 'type' => 'e2pdf-html',
1473 'block' => true,
1474 'float' => true,
1475 'properties' => array(
1476 'top' => '20',
1477 'left' => '20',
1478 'right' => '20',
1479 'width' => $width . '%',
1480 'height' => 'auto',
1481 'value' => $field['field_label'],
1482 ),
1483 )
1484 );
1485
1486 $days = array();
1487 $months = array();
1488 $years = array();
1489 if (class_exists('Forminator_Date')) {
1490 $forminator_date = new Forminator_Date();
1491 $options = $forminator_date->get_day();
1492 foreach ($options as $option) {
1493 $days[] = $option['value'];
1494 }
1495
1496 $options = $forminator_date->get_months();
1497 foreach ($options as $option) {
1498 $months[] = $option['value'];
1499 }
1500
1501 $options = $forminator_date->get_years(isset($field['min_year']) ? $field['min_year'] : '', isset($field['max_year']) ? $field['max_year'] : '');
1502 foreach ($options as $option) {
1503 $years[] = $option['value'];
1504 }
1505 }
1506
1507 $elements[] = $this->auto_field(
1508 $field,
1509 array(
1510 'type' => 'e2pdf-select',
1511 'properties' => array(
1512 'top' => '5',
1513 'width' => '30%',
1514 'height' => 'auto',
1515 'options' => implode("\n", $days),
1516 'value' => '{' . $field['element_id'] . '-month' . $repeater . '}',
1517 ),
1518 )
1519 );
1520
1521 $elements[] = $this->auto_field(
1522 $field,
1523 array(
1524 'type' => 'e2pdf-select',
1525 'float' => true,
1526 'properties' => array(
1527 'top' => '5',
1528 'left' => '5%',
1529 'right' => '5%',
1530 'width' => '40%',
1531 'height' => 'auto',
1532 'options' => implode("\n", $months),
1533 'value' => '{' . $field['element_id'] . '-day' . $repeater . '}',
1534 ),
1535 )
1536 );
1537
1538 $elements[] = $this->auto_field(
1539 $field,
1540 array(
1541 'type' => 'e2pdf-select',
1542 'float' => true,
1543 'properties' => array(
1544 'top' => '5',
1545 'width' => '30%',
1546 'height' => 'auto',
1547 'options' => implode("\n", $years),
1548 'value' => '{' . $field['element_id'] . '-year' . $repeater . '}',
1549 ),
1550 )
1551 );
1552 } elseif ($field['type'] == 'date' && $field['field_type'] == 'input') {
1553
1554 $elements[] = $this->auto_field(
1555 $field,
1556 array(
1557 'type' => 'e2pdf-html',
1558 'block' => true,
1559 'float' => true,
1560 'properties' => array(
1561 'top' => '20',
1562 'left' => '20',
1563 'right' => '20',
1564 'width' => $width . '%',
1565 'height' => 'auto',
1566 'value' => $field['field_label'],
1567 ),
1568 )
1569 );
1570
1571 $elements[] = $this->auto_field(
1572 $field,
1573 array(
1574 'type' => 'e2pdf-input',
1575 'properties' => array(
1576 'top' => '5',
1577 'width' => '30%',
1578 'height' => 'auto',
1579 'value' => '{' . $field['element_id'] . '-month' . $repeater . '}',
1580 ),
1581 )
1582 );
1583
1584 $elements[] = $this->auto_field(
1585 $field,
1586 array(
1587 'type' => 'e2pdf-input',
1588 'float' => true,
1589 'properties' => array(
1590 'top' => '5',
1591 'left' => '5%',
1592 'right' => '5%',
1593 'width' => '40%',
1594 'height' => 'auto',
1595 'value' => '{' . $field['element_id'] . '-day' . $repeater . '}',
1596 ),
1597 )
1598 );
1599
1600 $elements[] = $this->auto_field(
1601 $field,
1602 array(
1603 'float' => true,
1604 'type' => 'e2pdf-input',
1605 'properties' => array(
1606 'top' => '5',
1607 'width' => '30%',
1608 'height' => 'auto',
1609 'value' => '{' . $field['element_id'] . '-year' . $repeater . '}',
1610 ),
1611 )
1612 );
1613 } else {
1614
1615 $elements[] = $this->auto_field(
1616 $field,
1617 array(
1618 'type' => 'e2pdf-html',
1619 'block' => true,
1620 'float' => true,
1621 'properties' => array(
1622 'top' => '20',
1623 'left' => '20',
1624 'right' => '20',
1625 'width' => $width . '%',
1626 'height' => 'auto',
1627 'value' => $field['field_label'],
1628 ),
1629 )
1630 );
1631
1632 $elements[] = $this->auto_field(
1633 $field,
1634 array(
1635 'type' => 'e2pdf-input',
1636 'properties' => array(
1637 'top' => '5',
1638 'width' => '100%',
1639 'height' => 'auto',
1640 'value' => '{' . $field['element_id'] . $repeater . '}',
1641 ),
1642 )
1643 );
1644
1645 if (isset($field['description']) && $field['description']) {
1646 $elements[] = $this->auto_field(
1647 $field,
1648 array(
1649 'type' => 'e2pdf-html',
1650 'float' => false,
1651 'properties' => array(
1652 'top' => '5',
1653 'width' => '100%',
1654 'height' => 'auto',
1655 'value' => $field['description'],
1656 ),
1657 )
1658 );
1659 }
1660 }
1661 break;
1662 case 'postdata':
1663 if (isset($field['post_title']) && $field['post_title']) {
1664 if (isset($field['post_title_label']) && $field['post_title_label']) {
1665 $elements[] = $this->auto_field(
1666 $field,
1667 array(
1668 'type' => 'e2pdf-html',
1669 'block' => true,
1670 'float' => true,
1671 'properties' => array(
1672 'top' => '20',
1673 'left' => '20',
1674 'right' => '20',
1675 'width' => '100%',
1676 'height' => 'auto',
1677 'value' => $field['post_title_label'],
1678 ),
1679 )
1680 );
1681 }
1682 $elements[] = $this->auto_field(
1683 $field,
1684 array(
1685 'type' => 'e2pdf-input',
1686 'properties' => array(
1687 'top' => '5',
1688 'width' => '100%',
1689 'height' => 'auto',
1690 'value' => '{' . $field['element_id'] . '-post-title}',
1691 ),
1692 )
1693 );
1694 }
1695
1696 if (isset($field['post_content']) && $field['post_content']) {
1697 if (isset($field['post_content_label']) && $field['post_content_label']) {
1698 $elements[] = $this->auto_field(
1699 $field,
1700 array(
1701 'type' => 'e2pdf-html',
1702 'block' => true,
1703 'float' => true,
1704 'properties' => array(
1705 'top' => '20',
1706 'left' => '20',
1707 'right' => '20',
1708 'width' => '100%',
1709 'height' => 'auto',
1710 'value' => $field['post_content_label'],
1711 ),
1712 )
1713 );
1714 }
1715
1716 $elements[] = $this->auto_field(
1717 $field,
1718 array(
1719 'type' => 'e2pdf-textarea',
1720 'properties' => array(
1721 'top' => '5',
1722 'width' => '100%',
1723 'height' => 'auto',
1724 'value' => '{' . $field['element_id'] . '-post-content}',
1725 ),
1726 )
1727 );
1728 }
1729
1730 if (isset($field['post_excerpt']) && $field['post_excerpt']) {
1731 if (isset($field['post_excerpt_label']) && $field['post_excerpt_label']) {
1732 $elements[] = $this->auto_field(
1733 $field,
1734 array(
1735 'type' => 'e2pdf-html',
1736 'block' => true,
1737 'float' => true,
1738 'properties' => array(
1739 'top' => '20',
1740 'left' => '20',
1741 'right' => '20',
1742 'width' => '100%',
1743 'height' => 'auto',
1744 'value' => $field['post_excerpt_label'],
1745 ),
1746 )
1747 );
1748 }
1749
1750 $elements[] = $this->auto_field(
1751 $field,
1752 array(
1753 'type' => 'e2pdf-textarea',
1754 'properties' => array(
1755 'top' => '5',
1756 'width' => '100%',
1757 'height' => 'auto',
1758 'value' => '{' . $field['element_id'] . '-post-excerpt}',
1759 ),
1760 )
1761 );
1762 }
1763
1764 if (isset($field['post_image']) && $field['post_image']) {
1765 if (isset($field['post_image_label']) && $field['post_image_label']) {
1766 $elements[] = $this->auto_field(
1767 $field,
1768 array(
1769 'type' => 'e2pdf-html',
1770 'block' => true,
1771 'float' => true,
1772 'properties' => array(
1773 'top' => '20',
1774 'left' => '20',
1775 'right' => '20',
1776 'width' => '100%',
1777 'height' => 'auto',
1778 'value' => $field['post_image_label'],
1779 ),
1780 )
1781 );
1782 }
1783 $elements[] = $this->auto_field(
1784 $field,
1785 array(
1786 'type' => 'e2pdf-input',
1787 'properties' => array(
1788 'top' => '5',
1789 'width' => '100%',
1790 'height' => 'auto',
1791 'value' => '{' . $field['element_id'] . '-post-image}',
1792 ),
1793 )
1794 );
1795 }
1796
1797 if (isset($field['category']) && $field['category']) {
1798 if (isset($field['category_label']) && $field['category_label']) {
1799 $elements[] = $this->auto_field(
1800 $field,
1801 array(
1802 'type' => 'e2pdf-html',
1803 'block' => true,
1804 'float' => true,
1805 'properties' => array(
1806 'top' => '20',
1807 'left' => '20',
1808 'right' => '20',
1809 'width' => '100%',
1810 'height' => 'auto',
1811 'value' => $field['category_label'],
1812 ),
1813 )
1814 );
1815 }
1816 $elements[] = $this->auto_field(
1817 $field,
1818 array(
1819 'type' => 'e2pdf-input',
1820 'properties' => array(
1821 'top' => '5',
1822 'width' => '100%',
1823 'height' => 'auto',
1824 'value' => '{' . $field['element_id'] . '-category}',
1825 ),
1826 )
1827 );
1828 }
1829
1830 if (isset($field['post_tag']) && $field['post_tag']) {
1831 if (isset($field['post_tag_label']) && $field['post_tag_label']) {
1832 $elements[] = $this->auto_field(
1833 $field,
1834 array(
1835 'type' => 'e2pdf-html',
1836 'block' => true,
1837 'float' => true,
1838 'properties' => array(
1839 'top' => '20',
1840 'left' => '20',
1841 'right' => '20',
1842 'width' => '100%',
1843 'height' => 'auto',
1844 'value' => $field['post_tag_label'],
1845 ),
1846 )
1847 );
1848 }
1849 $elements[] = $this->auto_field(
1850 $field,
1851 array(
1852 'type' => 'e2pdf-input',
1853 'properties' => array(
1854 'top' => '5',
1855 'width' => '100%',
1856 'height' => 'auto',
1857 'value' => '{' . $field['element_id'] . '-post_tag}',
1858 ),
1859 )
1860 );
1861 }
1862
1863 if (isset($field['post_custom_fields']) && $field['post_custom_fields']) {
1864 $elements[] = $this->auto_field(
1865 $field,
1866 array(
1867 'type' => 'e2pdf-html',
1868 'block' => true,
1869 'float' => true,
1870 'properties' => array(
1871 'top' => '20',
1872 'left' => '20',
1873 'right' => '20',
1874 'width' => '100%',
1875 'height' => 'auto',
1876 'value' => __('Custom Fields', 'forminator'),
1877 ),
1878 )
1879 );
1880
1881 $elements[] = $this->auto_field(
1882 $field,
1883 array(
1884 'type' => 'e2pdf-input',
1885 'properties' => array(
1886 'top' => '5',
1887 'width' => '100%',
1888 'height' => 'auto',
1889 'value' => '{' . $field['element_id'] . '-post-custom}',
1890 ),
1891 )
1892 );
1893 }
1894 break;
1895
1896 case 'address':
1897 if (!$field['street_address'] && !$field['address_line']) {
1898
1899 if (!$field['address_city'] && !$field['address_state']) {
1900 if ($field['address_zip']) {
1901 $elements[] = $this->auto_field(
1902 $field,
1903 array(
1904 'type' => 'e2pdf-html',
1905 'block' => true,
1906 'float' => true,
1907 'properties' => array(
1908 'top' => '20',
1909 'left' => '20',
1910 'right' => '20',
1911 'width' => $field['address_country'] ? $width / 2 . '%' : $width . '%',
1912 'height' => 'auto',
1913 'value' => $field['address_zip_label'],
1914 ),
1915 )
1916 );
1917
1918 $elements[] = $this->auto_field(
1919 $field,
1920 array(
1921 'type' => 'e2pdf-input',
1922 'properties' => array(
1923 'top' => '5',
1924 'width' => '100%',
1925 'height' => 'auto',
1926 'value' => '{' . $field['element_id'] . '-zip' . $repeater . '}',
1927 ),
1928 )
1929 );
1930 }
1931
1932 if ($field['address_country']) {
1933 $elements[] = $this->auto_field(
1934 $field,
1935 array(
1936 'type' => 'e2pdf-html',
1937 'block' => true,
1938 'float' => true,
1939 'properties' => array(
1940 'top' => '20',
1941 'left' => '20',
1942 'right' => '20',
1943 'width' => $field['address_zip'] ? $width / 2 . '%' : $width . '%',
1944 'height' => 'auto',
1945 'value' => $field['address_country_label'],
1946 ),
1947 )
1948 );
1949
1950 $options_tmp = array();
1951 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1952 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1953 foreach ($options as $option) {
1954 $options_tmp[] = $option['value'];
1955 }
1956 }
1957
1958 $elements[] = $this->auto_field(
1959 $field,
1960 array(
1961 'type' => 'e2pdf-select',
1962 'properties' => array(
1963 'top' => '5',
1964 'width' => '100%',
1965 'height' => 'auto',
1966 'options' => implode("\n", $options_tmp),
1967 'value' => '{' . $field['element_id'] . '-country' . $repeater . '}',
1968 ),
1969 )
1970 );
1971 }
1972 } else {
1973
1974 if ($field['address_city']) {
1975 $elements[] = $this->auto_field(
1976 $field,
1977 array(
1978 'type' => 'e2pdf-html',
1979 'block' => true,
1980 'float' => true,
1981 'properties' => array(
1982 'top' => '20',
1983 'left' => '20',
1984 'right' => '20',
1985 'width' => $field['address_state'] ? $width / 2 . '%' : $width . '%',
1986 'height' => 'auto',
1987 'value' => $field['address_city_label'],
1988 ),
1989 )
1990 );
1991
1992 $elements[] = $this->auto_field(
1993 $field,
1994 array(
1995 'type' => 'e2pdf-input',
1996 'properties' => array(
1997 'top' => '5',
1998 'width' => '100%',
1999 'height' => 'auto',
2000 'value' => '{' . $field['element_id'] . '-city' . $repeater . '}',
2001 ),
2002 )
2003 );
2004
2005 if ($field['address_zip'] && $field['address_state']) {
2006 $elements[] = $this->auto_field(
2007 $field,
2008 array(
2009 'type' => 'e2pdf-html',
2010 'properties' => array(
2011 'top' => '20',
2012 'right' => $field['address_country'] ? '0' : '-40',
2013 'width' => $field['address_country'] ? '100%' : '200%',
2014 'height' => 'auto',
2015 'value' => $field['address_zip_label'],
2016 ),
2017 )
2018 );
2019
2020 $elements[] = $this->auto_field(
2021 $field,
2022 array(
2023 'type' => 'e2pdf-input',
2024 'properties' => array(
2025 'top' => '5',
2026 'right' => $field['address_country'] ? '0' : '-40',
2027 'width' => $field['address_country'] ? '100%' : '200%',
2028 'height' => 'auto',
2029 'value' => '{' . $field['element_id'] . '-zip' . $repeater . '}',
2030 ),
2031 )
2032 );
2033 } elseif ($field['address_country'] && !$field['address_zip'] && $field['address_state']) {
2034
2035 $elements[] = $this->auto_field(
2036 $field,
2037 array(
2038 'type' => 'e2pdf-html',
2039 'properties' => array(
2040 'top' => '20',
2041 'right' => $field['address_zip'] ? '0' : '-40',
2042 'width' => $field['address_zip'] ? '100%' : '200%',
2043 'height' => 'auto',
2044 'value' => $field['address_country_label'],
2045 ),
2046 )
2047 );
2048
2049 $options_tmp = array();
2050 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
2051 $options = forminator_to_field_array(forminator_get_countries_list(), true);
2052 foreach ($options as $option) {
2053 $options_tmp[] = $option['value'];
2054 }
2055 }
2056
2057 $elements[] = $this->auto_field(
2058 $field,
2059 array(
2060 'type' => 'e2pdf-select',
2061 'properties' => array(
2062 'top' => '5',
2063 'right' => $field['address_zip'] ? '0' : '-40',
2064 'width' => $field['address_zip'] ? '100%' : '200%',
2065 'height' => 'auto',
2066 'options' => implode("\n", $options_tmp),
2067 'value' => '{' . $field['element_id'] . '-country' . $repeater . '}',
2068 ),
2069 )
2070 );
2071 }
2072 }
2073
2074 if ($field['address_state']) {
2075 $elements[] = $this->auto_field(
2076 $field,
2077 array(
2078 'type' => 'e2pdf-html',
2079 'block' => true,
2080 'float' => true,
2081 'properties' => array(
2082 'top' => '20',
2083 'left' => '20',
2084 'right' => '20',
2085 'width' => $field['address_city'] ? ($width / 2) . '%' : $width . '%',
2086 'height' => 'auto',
2087 'value' => $field['address_state_label'],
2088 ),
2089 )
2090 );
2091
2092 $elements[] = $this->auto_field(
2093 $field,
2094 array(
2095 'type' => 'e2pdf-input',
2096 'properties' => array(
2097 'top' => '5',
2098 'width' => '100%',
2099 'height' => 'auto',
2100 'value' => '{' . $field['element_id'] . '-state' . $repeater . '}',
2101 ),
2102 )
2103 );
2104
2105 if ($field['address_country'] && $field['address_zip'] && $field['address_city']) {
2106
2107 $elements[] = $this->auto_field(
2108 $field,
2109 array(
2110 'type' => 'e2pdf-html',
2111 'properties' => array(
2112 'top' => '20',
2113 'right' => $field['address_zip'] ? '0' : '-40',
2114 'width' => $field['address_zip'] ? '100%' : '200%',
2115 'height' => 'auto',
2116 'value' => $field['address_country_label'],
2117 ),
2118 )
2119 );
2120
2121 $options_tmp = array();
2122 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
2123 $options = forminator_to_field_array(forminator_get_countries_list(), true);
2124 foreach ($options as $option) {
2125 $options_tmp[] = $option['value'];
2126 }
2127 }
2128
2129 $elements[] = $this->auto_field(
2130 $field,
2131 array(
2132 'type' => 'e2pdf-select',
2133 'properties' => array(
2134 'top' => '5',
2135 'right' => $field['address_zip'] ? '0' : '-40',
2136 'width' => $field['address_zip'] ? '100%' : '200%',
2137 'height' => 'auto',
2138 'options' => implode("\n", $options_tmp),
2139 'value' => '{' . $field['element_id'] . '-country' . $repeater . '}',
2140 ),
2141 )
2142 );
2143 }
2144 }
2145
2146 if (!$field['address_city'] || !$field['address_state']) {
2147 if ($field['address_zip']) {
2148 $elements[] = $this->auto_field(
2149 $field,
2150 array(
2151 'type' => 'e2pdf-html',
2152 'properties' => array(
2153 'top' => '20',
2154 'right' => $field['address_country'] ? '20' : '0',
2155 'width' => $field['address_country'] ? '50%' : '100%',
2156 'height' => 'auto',
2157 'value' => $field['address_zip_label'],
2158 ),
2159 )
2160 );
2161 }
2162
2163 if ($field['address_country']) {
2164
2165 $elements[] = $this->auto_field(
2166 $field,
2167 array(
2168 'type' => 'e2pdf-html',
2169 'float' => $field['address_zip'] ? true : false,
2170 'properties' => array(
2171 'top' => '20',
2172 'left' => $field['address_zip'] ? '20' : '0',
2173 'width' => $field['address_zip'] ? '50%' : '100%',
2174 'height' => 'auto',
2175 'value' => $field['address_country_label'],
2176 ),
2177 )
2178 );
2179 }
2180
2181 if ($field['address_zip']) {
2182 $elements[] = $this->auto_field(
2183 $field,
2184 array(
2185 'type' => 'e2pdf-input',
2186 'properties' => array(
2187 'top' => '5',
2188 'right' => $field['address_country'] ? '20' : '0',
2189 'width' => $field['address_country'] ? '50%' : '100%',
2190 'height' => 'auto',
2191 'value' => '{' . $field['element_id'] . '-zip' . $repeater . '}',
2192 ),
2193 )
2194 );
2195 }
2196
2197 if ($field['address_country']) {
2198 $options_tmp = array();
2199 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
2200 $options = forminator_to_field_array(forminator_get_countries_list(), true);
2201 foreach ($options as $option) {
2202 $options_tmp[] = $option['value'];
2203 }
2204 }
2205
2206 $elements[] = $this->auto_field(
2207 $field,
2208 array(
2209 'type' => 'e2pdf-select',
2210 'float' => $field['address_zip'] ? true : false,
2211 'properties' => array(
2212 'top' => '5',
2213 'left' => $field['address_zip'] ? '20' : '0',
2214 'width' => $field['address_zip'] ? '50%' : '100%',
2215 'height' => 'auto',
2216 'options' => implode("\n", $options_tmp),
2217 'value' => '{' . $field['element_id'] . '-country' . $repeater . '}',
2218 ),
2219 )
2220 );
2221 }
2222 }
2223 }
2224 } else {
2225
2226 if ($field['street_address']) {
2227 $elements[] = $this->auto_field(
2228 $field,
2229 array(
2230 'type' => 'e2pdf-html',
2231 'block' => true,
2232 'float' => true,
2233 'properties' => array(
2234 'top' => '20',
2235 'left' => '20',
2236 'right' => '20',
2237 'width' => $width . '%',
2238 'height' => 'auto',
2239 'value' => $field['street_address_label'],
2240 ),
2241 )
2242 );
2243
2244 $elements[] = $this->auto_field(
2245 $field,
2246 array(
2247 'type' => 'e2pdf-input',
2248 'properties' => array(
2249 'top' => '5',
2250 'width' => '100%',
2251 'height' => 'auto',
2252 'value' => '{' . $field['element_id'] . '-street_address' . $repeater . '}',
2253 ),
2254 )
2255 );
2256 }
2257
2258 if ($field['address_line']) {
2259
2260 if ($field['address_line_label']) {
2261 $elements[] = $this->auto_field(
2262 $field,
2263 array(
2264 'type' => 'e2pdf-html',
2265 'block' => $field['street_address'] ? false : true,
2266 'float' => $field['street_address'] ? false : true,
2267 'properties' => array(
2268 'top' => '20',
2269 'left' => $field['street_address'] ? '0' : '20',
2270 'right' => $field['street_address'] ? '0' : '20',
2271 'width' => $field['street_address'] ? '100%' : $width . '%',
2272 'height' => 'auto',
2273 'value' => $field['address_line_label'],
2274 ),
2275 )
2276 );
2277 }
2278
2279 $elements[] = $this->auto_field(
2280 $field,
2281 array(
2282 'type' => 'e2pdf-input',
2283 'properties' => array(
2284 'top' => $field['address_line_label'] ? '0' : '20',
2285 'width' => '100%',
2286 'height' => 'auto',
2287 'value' => '{' . $field['element_id'] . '-address_line' . $repeater . '}',
2288 ),
2289 )
2290 );
2291 }
2292
2293 if ($field['address_city']) {
2294
2295 $elements[] = $this->auto_field(
2296 $field,
2297 array(
2298 'type' => 'e2pdf-html',
2299 'properties' => array(
2300 'top' => '20',
2301 'right' => $field['address_state'] ? '20' : '0',
2302 'width' => $field['address_state'] ? '50%' : '100%',
2303 'height' => 'auto',
2304 'value' => $field['address_city_label'],
2305 ),
2306 )
2307 );
2308 }
2309
2310 if ($field['address_state']) {
2311 $elements[] = $this->auto_field(
2312 $field,
2313 array(
2314 'type' => 'e2pdf-html',
2315 'float' => $field['address_city'] ? true : false,
2316 'properties' => array(
2317 'top' => $field['address_city'] ? '0' : '20',
2318 'left' => $field['address_city'] ? '20' : '0',
2319 'width' => $field['address_city'] ? '50%' : '100%',
2320 'height' => 'auto',
2321 'value' => $field['address_state_label'],
2322 ),
2323 )
2324 );
2325 }
2326
2327 if ($field['address_city']) {
2328 $elements[] = $this->auto_field(
2329 $field,
2330 array(
2331 'type' => 'e2pdf-input',
2332 'properties' => array(
2333 'top' => '5',
2334 'right' => $field['address_state'] ? '20' : '0',
2335 'width' => $field['address_state'] ? '50%' : '100%',
2336 'height' => 'auto',
2337 'value' => '{' . $field['element_id'] . '-city' . $repeater . '}',
2338 ),
2339 )
2340 );
2341 }
2342
2343 if ($field['address_state']) {
2344 $elements[] = $this->auto_field(
2345 $field,
2346 array(
2347 'type' => 'e2pdf-input',
2348 'float' => $field['address_city'] ? true : false,
2349 'properties' => array(
2350 'top' => '5',
2351 'left' => $field['address_city'] ? '20' : '0',
2352 'width' => $field['address_city'] ? '50%' : '100%',
2353 'height' => 'auto',
2354 'value' => '{' . $field['element_id'] . '-state' . $repeater . '}',
2355 ),
2356 )
2357 );
2358 }
2359
2360 if ($field['address_zip']) {
2361
2362 $elements[] = $this->auto_field(
2363 $field,
2364 array(
2365 'type' => 'e2pdf-html',
2366 'properties' => array(
2367 'top' => '20',
2368 'right' => $field['address_country'] ? '20' : '0',
2369 'width' => $field['address_country'] ? '50%' : '100%',
2370 'height' => 'auto',
2371 'value' => $field['address_zip_label'],
2372 ),
2373 )
2374 );
2375 }
2376
2377 if ($field['address_country']) {
2378 $elements[] = $this->auto_field(
2379 $field,
2380 array(
2381 'type' => 'e2pdf-html',
2382 'float' => $field['address_zip'] ? true : false,
2383 'properties' => array(
2384 'top' => '20',
2385 'left' => $field['address_zip'] ? '20' : '0',
2386 'width' => $field['address_zip'] ? '50%' : '100%',
2387 'height' => 'auto',
2388 'value' => $field['address_country_label'],
2389 ),
2390 )
2391 );
2392 }
2393
2394 if ($field['address_zip']) {
2395 $elements[] = $this->auto_field(
2396 $field,
2397 array(
2398 'type' => 'e2pdf-input',
2399 'properties' => array(
2400 'top' => '5',
2401 'right' => $field['address_country'] ? '20' : '0',
2402 'width' => $field['address_country'] ? '50%' : '100%',
2403 'height' => 'auto',
2404 'value' => '{' . $field['element_id'] . '-zip' . $repeater . '}',
2405 ),
2406 )
2407 );
2408 }
2409
2410 if ($field['address_country']) {
2411 $options_tmp = array();
2412 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
2413 $options = forminator_to_field_array(forminator_get_countries_list(), true);
2414 foreach ($options as $option) {
2415 $options_tmp[] = $option['value'];
2416 }
2417 }
2418
2419 $elements[] = $this->auto_field(
2420 $field,
2421 array(
2422 'type' => 'e2pdf-select',
2423 'float' => $field['address_zip'] ? true : false,
2424 'properties' => array(
2425 'top' => '5',
2426 'left' => $field['address_zip'] ? '20' : '0',
2427 'width' => $field['address_zip'] ? '50%' : '100%',
2428 'height' => 'auto',
2429 'options' => implode("\n", $options_tmp),
2430 'value' => '{' . $field['element_id'] . '-country' . $repeater . '}',
2431 ),
2432 )
2433 );
2434 }
2435 }
2436 break;
2437 case 'time':
2438 $hours = array();
2439 $minutes = array();
2440
2441 if (class_exists('Forminator_Time')) {
2442 $forminator_time = new Forminator_Time();
2443 $options = $forminator_time->get_hours($field['time_type'], '', '', false);
2444 foreach ($options as $option) {
2445 $hours[] = $option['value'];
2446 }
2447
2448 $options = $forminator_time->get_minutes($field['time_type'], '', '', false);
2449 foreach ($options as $option) {
2450 $minutes[] = $option['value'];
2451 }
2452 }
2453
2454 $elements[] = $this->auto_field(
2455 $field,
2456 array(
2457 'type' => 'e2pdf-html',
2458 'block' => true,
2459 'float' => true,
2460 'properties' => array(
2461 'top' => '20',
2462 'left' => '20',
2463 'right' => '20',
2464 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
2465 'height' => 'auto',
2466 'value' => $field['hh_label'],
2467 ),
2468 )
2469 );
2470
2471 if ($field['field_type'] == 'select') {
2472 $elements[] = $this->auto_field(
2473 $field,
2474 array(
2475 'type' => 'e2pdf-select',
2476 'properties' => array(
2477 'top' => '5',
2478 'width' => '100%',
2479 'height' => 'auto',
2480 'options' => implode("\n", $hours),
2481 'value' => '{' . $field['element_id'] . '-hours' . $repeater . '}',
2482 ),
2483 )
2484 );
2485 } else {
2486 $elements[] = $this->auto_field(
2487 $field,
2488 array(
2489 'type' => 'e2pdf-input',
2490 'properties' => array(
2491 'top' => '5',
2492 'width' => '100%',
2493 'height' => 'auto',
2494 'value' => '{' . $field['element_id'] . '-hours' . $repeater . '}',
2495 ),
2496 )
2497 );
2498 }
2499
2500 $elements[] = $this->auto_field(
2501 $field,
2502 array(
2503 'type' => 'e2pdf-html',
2504 'block' => true,
2505 'float' => true,
2506 'properties' => array(
2507 'top' => '20',
2508 'left' => '20',
2509 'right' => '20',
2510 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
2511 'height' => 'auto',
2512 'value' => $field['mm_label'],
2513 ),
2514 )
2515 );
2516
2517 if ($field['field_type'] == 'select') {
2518 $elements[] = $this->auto_field(
2519 $field,
2520 array(
2521 'type' => 'e2pdf-select',
2522 'properties' => array(
2523 'top' => '5',
2524 'width' => '100%',
2525 'height' => 'auto',
2526 'options' => implode("\n", $minutes),
2527 'value' => '{' . $field['element_id'] . '-minutes' . $repeater . '}',
2528 ),
2529 )
2530 );
2531 } else {
2532 $elements[] = $this->auto_field(
2533 $field,
2534 array(
2535 'type' => 'e2pdf-input',
2536 'properties' => array(
2537 'top' => '5',
2538 'width' => '100%',
2539 'height' => 'auto',
2540 'value' => '{' . $field['element_id'] . '-minutes' . $repeater . '}',
2541 ),
2542 )
2543 );
2544 }
2545
2546 if ($field['time_type'] == 'twelve') {
2547 $elements[] = $this->auto_field(
2548 $field,
2549 array(
2550 'type' => 'e2pdf-html',
2551 'block' => true,
2552 'float' => true,
2553 'properties' => array(
2554 'top' => '20',
2555 'left' => '20',
2556 'right' => '20',
2557 'width' => ($width / 3) . '%',
2558 'height' => 'auto',
2559 'value' => '',
2560 ),
2561 )
2562 );
2563
2564 $ampm = array(
2565 'am', 'pm',
2566 );
2567
2568 $elements[] = $this->auto_field(
2569 $field,
2570 array(
2571 'type' => 'e2pdf-select',
2572 'properties' => array(
2573 'top' => '5',
2574 'width' => '100%',
2575 'height' => 'auto',
2576 'options' => implode("\n", $ampm),
2577 'value' => '{' . $field['element_id'] . '-ampm' . $repeater . '}',
2578 ),
2579 )
2580 );
2581 }
2582 break;
2583 case 'html':
2584 if ($field['field_label']) {
2585 $elements[] = $this->auto_field(
2586 $field,
2587 array(
2588 'type' => 'e2pdf-html',
2589 'block' => true,
2590 'properties' => array(
2591 'top' => '20',
2592 'left' => '20',
2593 'right' => '20',
2594 'width' => $width . '%',
2595 'height' => 'auto',
2596 'value' => $field['field_label'],
2597 ),
2598 )
2599 );
2600
2601 $elements[] = $this->auto_field(
2602 $field,
2603 array(
2604 'type' => 'e2pdf-html',
2605 'properties' => array(
2606 'top' => '5',
2607 'width' => '100%',
2608 'height' => 'auto',
2609 'value' => $field['variations'],
2610 ),
2611 )
2612 );
2613 } else {
2614 $elements[] = $this->auto_field(
2615 $field,
2616 array(
2617 'type' => 'e2pdf-html',
2618 'block' => true,
2619 'properties' => array(
2620 'top' => '20',
2621 'left' => '20',
2622 'right' => '20',
2623 'width' => $width . '%',
2624 'height' => 'auto',
2625 'value' => $field['variations'],
2626 ),
2627 )
2628 );
2629 }
2630 break;
2631 case 'section':
2632 $section = '';
2633 if ($field['section_title']) {
2634 $section .= '<h2>' . $field['section_title'] . '</h2>';
2635 }
2636 if (isset($field['section_subtitle']) && $field['section_subtitle']) {
2637 $section .= $field['section_subtitle'];
2638 }
2639 if ($section) {
2640 $elements[] = $this->auto_field(
2641 $field,
2642 array(
2643 'type' => 'e2pdf-html',
2644 'block' => true,
2645 'properties' => array(
2646 'top' => '20',
2647 'left' => '20',
2648 'right' => '20',
2649 'width' => $width . '%',
2650 'height' => 'auto',
2651 'value' => $section,
2652 ),
2653 )
2654 );
2655 }
2656 break;
2657 case 'text':
2658 $elements[] = $this->auto_field(
2659 $field,
2660 array(
2661 'type' => 'e2pdf-html',
2662 'block' => true,
2663 'float' => true,
2664 'properties' => array(
2665 'top' => '20',
2666 'left' => '20',
2667 'right' => '20',
2668 'width' => $width . '%',
2669 'height' => 'auto',
2670 'value' => $field['field_label'],
2671 ),
2672 )
2673 );
2674
2675 if (isset($field['input_type']) && $field['input_type'] == 'line') {
2676 $elements[] = $this->auto_field(
2677 $field,
2678 array(
2679 'type' => 'e2pdf-input',
2680 'properties' => array(
2681 'top' => '5',
2682 'width' => '100%',
2683 'height' => 'auto',
2684 'value' => '{' . $field['element_id'] . $repeater . '}',
2685 ),
2686 )
2687 );
2688 } else {
2689 $elements[] = $this->auto_field(
2690 $field,
2691 array(
2692 'type' => 'e2pdf-textarea',
2693 'properties' => array(
2694 'top' => '5',
2695 'width' => '100%',
2696 'height' => 'auto',
2697 'value' => '{' . $field['element_id'] . $repeater . '}',
2698 ),
2699 )
2700 );
2701 }
2702
2703 if (isset($field['description']) && $field['description']) {
2704 $elements[] = $this->auto_field(
2705 $field,
2706 array(
2707 'type' => 'e2pdf-html',
2708 'float' => false,
2709 'properties' => array(
2710 'top' => '5',
2711 'width' => '100%',
2712 'height' => 'auto',
2713 'value' => $field['description'],
2714 ),
2715 )
2716 );
2717 }
2718 break;
2719 case 'upload':
2720 case 'textarea':
2721 $elements[] = $this->auto_field(
2722 $field,
2723 array(
2724 'type' => 'e2pdf-html',
2725 'block' => true,
2726 'float' => true,
2727 'properties' => array(
2728 'top' => '20',
2729 'left' => '20',
2730 'right' => '20',
2731 'width' => $width . '%',
2732 'height' => 'auto',
2733 'value' => $field['field_label'],
2734 ),
2735 )
2736 );
2737 $elements[] = $this->auto_field(
2738 $field,
2739 array(
2740 'type' => 'e2pdf-textarea',
2741 'properties' => array(
2742 'top' => '5',
2743 'width' => '100%',
2744 'height' => 'auto',
2745 'value' => '{' . $field['element_id'] . $repeater . '}',
2746 'text_auto_font_size' => '1',
2747 ),
2748 )
2749 );
2750
2751 if (isset($field['description']) && $field['description']) {
2752 $elements[] = $this->auto_field(
2753 $field,
2754 array(
2755 'type' => 'e2pdf-html',
2756 'float' => false,
2757 'properties' => array(
2758 'top' => '5',
2759 'width' => '100%',
2760 'height' => 'auto',
2761 'value' => $field['description'],
2762 ),
2763 )
2764 );
2765 }
2766 break;
2767 case 'slider':
2768 $elements[] = $this->auto_field(
2769 $field,
2770 array(
2771 'type' => 'e2pdf-html',
2772 'block' => true,
2773 'float' => true,
2774 'properties' => array(
2775 'top' => '20',
2776 'left' => '20',
2777 'right' => '20',
2778 'width' => $width . '%',
2779 'height' => 'auto',
2780 'value' => $field['field_label'],
2781 ),
2782 )
2783 );
2784
2785 if (isset($field['slider_type']) && $field['slider_type'] == 'range') {
2786 $elements[] = $this->auto_field(
2787 $field,
2788 array(
2789 'float' => true,
2790 'type' => 'e2pdf-input',
2791 'properties' => array(
2792 'top' => '5',
2793 'right' => '20',
2794 'width' => '50%',
2795 'height' => 'auto',
2796 'value' => '{' . $field['element_id'] . '-min' . $repeater . '}',
2797 ),
2798 )
2799 );
2800 $elements[] = $this->auto_field(
2801 $field,
2802 array(
2803 'float' => true,
2804 'type' => 'e2pdf-input',
2805 'properties' => array(
2806 'top' => '5',
2807 'left' => '20',
2808 'width' => '50%',
2809 'height' => 'auto',
2810 'value' => '{' . $field['element_id'] . '-max' . $repeater . '}',
2811 ),
2812 )
2813 );
2814 } else {
2815 $elements[] = $this->auto_field(
2816 $field,
2817 array(
2818 'type' => 'e2pdf-input',
2819 'properties' => array(
2820 'top' => '5',
2821 'width' => '100%',
2822 'height' => 'auto',
2823 'value' => '{' . $field['element_id'] . $repeater . '}',
2824 ),
2825 )
2826 );
2827 }
2828 if (isset($field['description']) && $field['description']) {
2829 $elements[] = $this->auto_field(
2830 $field,
2831 array(
2832 'type' => 'e2pdf-html',
2833 'float' => false,
2834 'properties' => array(
2835 'top' => '5',
2836 'width' => '100%',
2837 'height' => 'auto',
2838 'value' => $field['description'],
2839 ),
2840 )
2841 );
2842 }
2843 break;
2844 case 'signature':
2845 $elements[] = $this->auto_field(
2846 $field,
2847 array(
2848 'type' => 'e2pdf-html',
2849 'block' => true,
2850 'float' => true,
2851 'properties' => array(
2852 'top' => '20',
2853 'left' => '20',
2854 'right' => '20',
2855 'width' => $width . '%',
2856 'height' => 'auto',
2857 'value' => $field['field_label'],
2858 ),
2859 )
2860 );
2861 $elements[] = $this->auto_field(
2862 $field,
2863 array(
2864 'type' => 'e2pdf-signature',
2865 'properties' => array(
2866 'top' => '5',
2867 'width' => '100%',
2868 'height' => '150',
2869 'dimension' => '1',
2870 'block_dimension' => '1',
2871 'value' => '{' . $field['element_id'] . $repeater . '}',
2872 ),
2873 )
2874 );
2875
2876 if (isset($field['description']) && $field['description']) {
2877 $elements[] = $this->auto_field(
2878 $field,
2879 array(
2880 'type' => 'e2pdf-html',
2881 'float' => false,
2882 'properties' => array(
2883 'top' => '5',
2884 'width' => '100%',
2885 'height' => 'auto',
2886 'value' => $field['description'],
2887 ),
2888 )
2889 );
2890 }
2891 break;
2892 case 'select':
2893 $elements[] = $this->auto_field(
2894 $field,
2895 array(
2896 'type' => 'e2pdf-html',
2897 'block' => true,
2898 'float' => true,
2899 'properties' => array(
2900 'top' => '20',
2901 'left' => '20',
2902 'right' => '20',
2903 'width' => $width . '%',
2904 'height' => 'auto',
2905 'value' => $field['field_label'],
2906 ),
2907 )
2908 );
2909
2910 if ($field['value_type'] == 'radio') {
2911 foreach ($field['options'] as $opt_key => $option) {
2912 if (is_array($option)) {
2913 $elements[] = $this->auto_field(
2914 $field,
2915 array(
2916 'type' => 'e2pdf-radio',
2917 'properties' => array(
2918 'top' => '5',
2919 'width' => 'auto',
2920 'height' => 'auto',
2921 'value' => '{' . $field['element_id'] . $repeater . '}',
2922 'option' => $option['value'] && !$use_labels ? $option['value'] : $option['label'],
2923 'group' => '{' . $field['element_id'] . $repeater . '}',
2924 ),
2925 )
2926 );
2927 $elements[] = $this->auto_field(
2928 $field,
2929 array(
2930 'type' => 'e2pdf-html',
2931 'float' => true,
2932 'properties' => array(
2933 'left' => '5',
2934 'width' => '100%',
2935 'height' => 'auto',
2936 'value' => $option['label'],
2937 ),
2938 )
2939 );
2940 }
2941 }
2942 } else {
2943 $options_tmp = array();
2944 foreach ($field['options'] as $option) {
2945 $options_tmp[] = $option['value'] && !$use_labels ? $option['value'] : $option['label'];
2946 }
2947 $elements[] = $this->auto_field(
2948 $field,
2949 array(
2950 'type' => 'e2pdf-select',
2951 'properties' => array(
2952 'top' => '5',
2953 'width' => '100%',
2954 'height' => 'auto',
2955 'options' => implode("\n", $options_tmp),
2956 'value' => '{' . $field['element_id'] . $repeater . '}',
2957 ),
2958 )
2959 );
2960 }
2961
2962 if (isset($field['description']) && $field['description']) {
2963 $elements[] = $this->auto_field(
2964 $field,
2965 array(
2966 'type' => 'e2pdf-html',
2967 'float' => false,
2968 'properties' => array(
2969 'top' => '5',
2970 'width' => '100%',
2971 'height' => 'auto',
2972 'value' => $field['description'],
2973 ),
2974 )
2975 );
2976 }
2977 break;
2978 case 'consent':
2979 $elements[] = $this->auto_field(
2980 $field,
2981 array(
2982 'type' => 'e2pdf-html',
2983 'block' => true,
2984 'float' => true,
2985 'properties' => array(
2986 'top' => '20',
2987 'left' => '20',
2988 'right' => '20',
2989 'width' => $width . '%',
2990 'height' => 'auto',
2991 'value' => $field['field_label'],
2992 ),
2993 )
2994 );
2995
2996 $elements[] = $this->auto_field(
2997 $field,
2998 array(
2999 'type' => 'e2pdf-checkbox',
3000 'properties' => array(
3001 'top' => '5',
3002 'width' => 'auto',
3003 'height' => 'auto',
3004 'value' => '{' . $field['element_id'] . $repeater . '}',
3005 'option' => 'checked',
3006 ),
3007 )
3008 );
3009
3010 $elements[] = $this->auto_field(
3011 $field,
3012 array(
3013 'type' => 'e2pdf-html',
3014 'float' => true,
3015 'properties' => array(
3016 'left' => '5',
3017 'width' => '100%',
3018 'height' => 'auto',
3019 'value' => $field['consent_description'],
3020 ),
3021 )
3022 );
3023 break;
3024 case 'checkbox':
3025 $elements[] = $this->auto_field(
3026 $field,
3027 array(
3028 'type' => 'e2pdf-html',
3029 'block' => true,
3030 'float' => true,
3031 'properties' => array(
3032 'top' => '20',
3033 'left' => '20',
3034 'right' => '20',
3035 'width' => $width . '%',
3036 'height' => 'auto',
3037 'value' => $field['field_label'],
3038 ),
3039 )
3040 );
3041
3042 if ($field['value_type'] == 'multiselect') {
3043 $options_tmp = array();
3044 foreach ($field['options'] as $opt_key => $option) {
3045 $options_tmp[] = $option['value'] && !$use_labels ? $option['value'] : $option['label'];
3046 }
3047 $elements[] = $this->auto_field(
3048 $field,
3049 array(
3050 'type' => 'e2pdf-select',
3051 'properties' => array(
3052 'top' => '5',
3053 'width' => '100%',
3054 'height' => '44',
3055 'multiline' => '1',
3056 'options' => implode("\n", $options_tmp),
3057 'value' => '{' . $field['element_id'] . $repeater . '}',
3058 ),
3059 )
3060 );
3061 } else {
3062 foreach ($field['options'] as $opt_key => $option) {
3063 if (is_array($option)) {
3064 $elements[] = $this->auto_field(
3065 $field,
3066 array(
3067 'type' => 'e2pdf-checkbox',
3068 'properties' => array(
3069 'top' => '5',
3070 'width' => 'auto',
3071 'height' => 'auto',
3072 'value' => '{' . $field['element_id'] . $repeater . '}',
3073 'option' => $option['value'] && !$use_labels ? $option['value'] : $option['label'],
3074 ),
3075 )
3076 );
3077 $elements[] = $this->auto_field(
3078 $field,
3079 array(
3080 'type' => 'e2pdf-html',
3081 'float' => true,
3082 'properties' => array(
3083 'left' => '5',
3084 'width' => '100%',
3085 'height' => 'auto',
3086 'value' => $option['label'],
3087 ),
3088 )
3089 );
3090 }
3091 }
3092 }
3093
3094 if (isset($field['description']) && $field['description']) {
3095 $elements[] = $this->auto_field(
3096 $field,
3097 array(
3098 'type' => 'e2pdf-html',
3099 'float' => false,
3100 'properties' => array(
3101 'top' => '5',
3102 'width' => '100%',
3103 'height' => 'auto',
3104 'value' => $field['description'],
3105 ),
3106 )
3107 );
3108 }
3109 break;
3110
3111 case 'radio':
3112 $elements[] = $this->auto_field(
3113 $field,
3114 array(
3115 'type' => 'e2pdf-html',
3116 'block' => true,
3117 'float' => true,
3118 'properties' => array(
3119 'top' => '20',
3120 'left' => '20',
3121 'right' => '20',
3122 'width' => $width . '%',
3123 'height' => 'auto',
3124 'value' => $field['field_label'],
3125 ),
3126 )
3127 );
3128
3129 foreach ($field['options'] as $opt_key => $option) {
3130 if (is_array($option)) {
3131 $elements[] = $this->auto_field(
3132 $field,
3133 array(
3134 'type' => 'e2pdf-radio',
3135 'properties' => array(
3136 'top' => '5',
3137 'width' => 'auto',
3138 'height' => 'auto',
3139 'value' => '{' . $field['element_id'] . $repeater . '}',
3140 'option' => $option['value'] && !$use_labels ? $option['value'] : $option['label'],
3141 'group' => '{' . $field['element_id'] . $repeater . '}',
3142 ),
3143 )
3144 );
3145 $elements[] = $this->auto_field(
3146 $field,
3147 array(
3148 'type' => 'e2pdf-html',
3149 'float' => true,
3150 'properties' => array(
3151 'left' => '5',
3152 'width' => '100%',
3153 'height' => 'auto',
3154 'value' => $option['label'],
3155 ),
3156 )
3157 );
3158 }
3159 }
3160
3161 if (isset($field['description']) && $field['description']) {
3162 $elements[] = $this->auto_field(
3163 $field,
3164 array(
3165 'type' => 'e2pdf-html',
3166 'float' => false,
3167 'properties' => array(
3168 'top' => '5',
3169 'width' => '100%',
3170 'height' => 'auto',
3171 'value' => $field['description'],
3172 ),
3173 )
3174 );
3175 }
3176 break;
3177
3178 case 'gdprcheckbox':
3179 $elements[] = $this->auto_field(
3180 $field,
3181 array(
3182 'type' => 'e2pdf-html',
3183 'block' => true,
3184 'float' => true,
3185 'properties' => array(
3186 'top' => '20',
3187 'left' => '20',
3188 'right' => '20',
3189 'width' => $width . '%',
3190 'height' => 'auto',
3191 'value' => '',
3192 ),
3193 )
3194 );
3195
3196 $elements[] = $this->auto_field(
3197 $field,
3198 array(
3199 'type' => 'e2pdf-checkbox',
3200 'properties' => array(
3201 'top' => '5',
3202 'width' => 'auto',
3203 'height' => 'auto',
3204 'value' => '{' . $field['element_id'] . $repeater . '}',
3205 'option' => 'true',
3206 ),
3207 )
3208 );
3209 $elements[] = $this->auto_field(
3210 $field,
3211 array(
3212 'type' => 'e2pdf-html',
3213 'float' => true,
3214 'properties' => array(
3215 'left' => '5',
3216 'width' => '100%',
3217 'height' => 'auto',
3218 'value' => $field['gdpr_description'],
3219 ),
3220 )
3221 );
3222 break;
3223 default:
3224 break;
3225 }
3226 }
3227 }
3228
3229 $response['page'] = array(
3230 'bottom' => '20',
3231 'top' => '20',
3232 'left' => '20',
3233 'right' => '20',
3234 );
3235
3236 $response['elements'] = $elements;
3237 return $response;
3238 }
3239
3240 // auto field
3241 public function auto_field($field = false, $element = array()) {
3242 if (!$field) {
3243 return false;
3244 }
3245 if (!isset($element['block'])) {
3246 $element['block'] = false;
3247 }
3248 if (!isset($element['float'])) {
3249 $element['float'] = false;
3250 }
3251 return $element;
3252 }
3253
3254 // load actions
3255 public function load_actions() {
3256 add_action('forminator_custom_form_submit_before_set_fields', array($this, 'action_forminator_custom_form_submit_before_set_fields'), 30, 3);
3257 add_action('forminator_custom_form_mail_admin_sent', array($this, 'action_forminator_custom_form_mail_admin_sent'), 30, 5);
3258 }
3259
3260 // load filters
3261 public function load_filters() {
3262 add_filter('forminator_custom_form_mail_admin_message', array($this, 'filter_forminator_mail_message'), 30, 5);
3263 add_filter('forminator_custom_form_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30);
3264 add_filter('forminator_custom_form_ajax_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30);
3265
3266 // forminator 1.14.11 compatibility fix
3267 add_filter('forminator_form_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30);
3268 add_filter('forminator_form_ajax_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30);
3269 }
3270
3271 // before set fields action
3272 public function action_forminator_custom_form_submit_before_set_fields($entry, $form_id, $field_data_array) {
3273 if (class_exists('Forminator_API')) {
3274 $form = Forminator_API::get_form($form_id);
3275 if (!is_wp_error($form)) {
3276 if ($form->is_prevent_store()) {
3277 $this->set('field_data_array', $field_data_array);
3278 $this->set('item', $form_id);
3279 $this->set('dataset', 'is_prevent_store');
3280 } elseif ($entry && isset($entry->entry_id)) {
3281 $this->set('dataset', $entry->entry_id);
3282 foreach ($field_data_array as $key => $field) {
3283 if (isset($field['field_array']['custom_value']) && is_string($field['field_array']['custom_value']) && false !== strpos($field['field_array']['custom_value'], '[e2pdf-download')) {
3284 Forminator_Front_Action::$info['field_data_array'][$key]['value'] = $this->filter_content($field['field_array']['custom_value']);
3285 }
3286 }
3287 }
3288 }
3289 }
3290 }
3291
3292 // mail admin sent action
3293 public function action_forminator_custom_form_mail_admin_sent($mail, $custom_form, $data, $entry, $recipients) {
3294 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 30);
3295 $files = $this->helper->get('forminator_attachments');
3296 if (is_array($files) && !empty($files)) {
3297
3298 $saved = $this->helper->get('forminator_saved_attachments');
3299 if (!is_array($saved)) {
3300 $saved = array();
3301 }
3302 foreach ($files as $key => $file) {
3303 if (!in_array($file, $saved, false)) {
3304 $this->helper->delete_dir(dirname($file) . '/');
3305 }
3306 }
3307 $this->helper->deset('forminator_attachments');
3308 $this->helper->deset('forminator_saved_attachments');
3309 }
3310 }
3311
3312 // mail message filter
3313 public function filter_forminator_mail_message($message, $custom_form, $data, $entry, $mail) {
3314 if (isset($message) && false !== strpos($message, '[')) {
3315 $shortcode_tags = array(
3316 'e2pdf-download',
3317 'e2pdf-save',
3318 'e2pdf-attachment',
3319 'e2pdf-adobesign',
3320 'e2pdf-zapier',
3321 );
3322
3323 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
3324 $tagnames = array_intersect($shortcode_tags, $matches[1]);
3325 if (!empty($tagnames)) {
3326 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
3327 foreach ($shortcodes[0] as $key => $shortcode_value) {
3328 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
3329 $atts = shortcode_parse_atts($shortcode[3]);
3330 $file = false;
3331 if (!isset($atts['dataset']) && isset($atts['id'])) {
3332 $template = new Model_E2pdf_Template();
3333 $template->load($atts['id']);
3334 if ($template->get('extension') === 'forminator') {
3335 if ($this->get('dataset')) {
3336 $entry_id = $this->get('dataset');
3337 } else {
3338 $entry_id = isset($entry->entry_id) ? $entry->entry_id : false;
3339 }
3340 if ($entry_id) {
3341 if (($shortcode[2] === 'e2pdf-download' || $shortcode[2] === 'e2pdf-view' || $shortcode[2] === 'e2pdf-zapier') && $entry_id == 'is_prevent_store') { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
3342 } else {
3343 if ($entry_id == 'is_prevent_store') {
3344 add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
3345 }
3346 $atts['dataset'] = $entry_id;
3347 $shortcode[3] .= ' dataset="' . $entry_id . '"';
3348 }
3349 }
3350 }
3351 }
3352 if (!isset($atts['apply'])) {
3353 $shortcode[3] .= ' apply="true"';
3354 }
3355 if (!isset($atts['filter'])) {
3356 $shortcode[3] .= ' filter="true"';
3357 }
3358 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
3359 $file = do_shortcode_tag($shortcode);
3360 if ($file) {
3361 $tmp = false;
3362 if (substr($file, 0, 4) === 'tmp:') {
3363 $file = substr($file, 4);
3364 $tmp = true;
3365 }
3366 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
3367 if (!$tmp) {
3368 $this->helper->add('forminator_saved_attachments', $file);
3369 }
3370 }
3371 $this->helper->add('forminator_attachments', $file);
3372 }
3373 $message = str_replace($shortcode_value, '', $message);
3374 } else {
3375 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
3376 }
3377 remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
3378 }
3379
3380 add_filter('wp_mail', array($this, 'filter_wp_mail'), 30);
3381 }
3382 }
3383 return $message;
3384 }
3385
3386 // extension options filter
3387 public function filter_e2pdf_model_shortcode_extension_options($options) {
3388 if ($this->get('dataset') && $this->get('dataset') == 'is_prevent_store') {
3389 $options['field_data_array'] = $this->get('field_data_array');
3390 }
3391 return $options;
3392 }
3393
3394 // submit response filter
3395 public function filter_forminator_custom_form_submit_response($response) {
3396 if (isset($response['message']) && false !== strpos($response['message'], '[') && isset($response['success']) && $response['success']) {
3397 $response['message'] = $this->filter_content($response['message'], 'message');
3398 }
3399 return $response;
3400 }
3401
3402 // content filter
3403 public function filter_content($content, $type = '') {
3404
3405 if (false !== strpos($content, '[')) {
3406 $shortcode_tags = array(
3407 'e2pdf-download',
3408 'e2pdf-save',
3409 'e2pdf-view',
3410 'e2pdf-adobesign',
3411 'e2pdf-zapier',
3412 );
3413 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
3414 $tagnames = array_intersect($shortcode_tags, $matches[1]);
3415 if (!empty($tagnames)) {
3416 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
3417 foreach ($shortcodes[0] as $key => $shortcode_value) {
3418 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
3419 $atts = shortcode_parse_atts($shortcode[3]);
3420 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
3421 } else {
3422 if (!isset($atts['dataset']) && isset($atts['id'])) {
3423 $template = new Model_E2pdf_Template();
3424 $template->load($atts['id']);
3425 if ($template->get('extension') === 'forminator') {
3426 $entry_id = $this->get('dataset');
3427 if ($entry_id) {
3428 if (($shortcode[2] === 'e2pdf-download' || $shortcode[2] === 'e2pdf-view' || $shortcode[2] === 'e2pdf-zapier') && $entry_id == 'is_prevent_store') { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
3429 } else {
3430 if ($entry_id == 'is_prevent_store') {
3431 add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
3432 }
3433 $atts['dataset'] = $entry_id;
3434 $shortcode[3] .= ' dataset="' . $entry_id . '"';
3435 }
3436 }
3437 }
3438 }
3439
3440 if (!isset($atts['apply'])) {
3441 $shortcode[3] .= ' apply="true"';
3442 }
3443 if (!isset($atts['filter'])) {
3444 $shortcode[3] .= ' filter="true"';
3445 }
3446 if (!isset($atts['iframe_download']) && $type == 'message') {
3447 $shortcode[3] .= ' iframe_download="true"';
3448 }
3449 $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
3450 remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
3451 }
3452 }
3453 }
3454 }
3455 return $content;
3456 }
3457
3458 // wp mail filter
3459 public function filter_wp_mail($args = array()) {
3460 $files = $this->helper->get('forminator_attachments');
3461 if (is_array($files) && !empty($files)) {
3462 foreach ($files as $file) {
3463 $args['attachments'][] = $file;
3464 }
3465 }
3466 $wp_mail = array(
3467 'to' => $args['to'],
3468 'subject' => $args['subject'],
3469 'message' => $args['message'],
3470 'headers' => $args['headers'],
3471 'attachments' => $args['attachments'],
3472 );
3473
3474 return $wp_mail;
3475 }
3476
3477 // styles
3478 public function styles($item_id = false) {
3479 $styles = array();
3480 if (function_exists('forminator_plugin_url') && class_exists('Forminator_API')) {
3481 if (defined('FORMINATOR_VERSION')) {
3482 $version = FORMINATOR_VERSION;
3483 } else {
3484 $version = '0';
3485 }
3486 $styles = array();
3487 if ($item_id) {
3488 $forminator_form = Forminator_API::get_form($item_id);
3489 if (!is_wp_error($forminator_form)) {
3490 $form_settings = isset($forminator_form->settings) ? $forminator_form->settings : array();
3491 if (isset($form_settings['form-style']) && $form_settings['form-style']) {
3492 $form_design = $form_settings['form-style'];
3493 } else {
3494 $form_design = 'default';
3495 }
3496
3497 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/forminator-icons.min.css?v=' . $version;
3498 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/forminator-utilities.min.css?v=' . $version;
3499
3500 if (isset($form_settings['fields-style']) && 'open' === $form_settings['fields-style']) {
3501 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/grid/forminator-grid.open.min.css?v=' . $version;
3502 } elseif (isset($form_settings['fields-style']) && 'enclosed' === $form_settings['fields-style']) {
3503 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/grid/forminator-grid.enclosed.min.css?v=' . $version;
3504 }
3505 if ('none' !== $form_design) {
3506 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/form/forminator-form-' . $form_design . '.base.min.css?v=' . $version;
3507 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/form/forminator-form-' . $form_design . '.full.min.css?v=' . $version;
3508 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/form/forminator-form-' . $form_design . '.pagination.min.css?v=' . $version;
3509 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/form/select2.min.css?v=' . $version;
3510 $styles[] = forminator_plugin_url() . 'assets/forminator-ui/css/src/form/forminator-authentication.min.css?v=' . $version;
3511 }
3512 $styles[] = plugins_url('css/extension/forminator.css?v=' . time(), $this->helper->get('plugin_file_path'));
3513 }
3514 }
3515 }
3516 return $styles;
3517 }
3518 }
3519