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