PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.5.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.5.2
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Form / FormManager.php

FormManager.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.5.2, at includes/Core/Form/FormManager.php

645 lines 25.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Get set Form,fields
5 */
6
7 namespace BitCode\BitForm\Core\Form;
8
9 /**
10 * FrontendFormManager class
11 */
12
13 use WP_Error;
14 use BitCode\BitForm\Core\Util\IpTool;
15 use BitCode\BitForm\Core\Form\ApiResponse;
16 use BitCode\BitForm\Core\Util\FileHandler;
17 use BitCode\BitForm\Core\Database\FormModel;
18 use BitCode\BitForm\Core\Database\FormEntryModel;
19 use BitCode\BitForm\Core\Database\FormEntryLogModel;
20 use BitCode\BitForm\Core\WorkFlow\WorkFlowRunHelper;
21 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
22 use BitCode\BitForm\Core\Form\Validator\FormFieldValidator;
23 use BitCode\BitForm\Admin\Form\CustomFieldHandler;
24 use BitCode\BitForm\Core\Integration\IntegrationHandler;
25 use BitCode\BitForm\Core\Util\FieldValueHandler;
26
27 class FormManager
28 {
29 protected static $form;
30 protected $formModel;
31 protected $form_id;
32 private $_has_upload;
33 private $_field_label;
34 private $_fields;
35 public function __construct($form_id)
36 {
37 $this->form_id = $form_id;
38 $this->formModel = new FormModel();
39
40 static::$form = $this->formModel->get(
41 [
42 "id",
43 "form_content",
44 "form_name",
45 'created_at',
46 'views',
47 'entries',
48 'status'
49 ],
50 array(
51 'id' => $form_id
52 )
53 );
54 }
55
56 public function isExist()
57 {
58 return (!static::$form || is_wp_error(static::$form)) ? false : true;
59 }
60
61 public function checkStatus()
62 {
63 return static::$form[0]->status === '1' ? true : false;
64 }
65
66 public function getFormContentWithValue($defaultValues)
67 {
68 $form_content = \json_decode(static::$form[0]->form_content);
69 if (!is_array($defaultValues)) {
70 return $form_content;
71 }
72 foreach ($form_content->fields as $fieldKey => $fieldDetails) {
73 // $field_name = empty($fieldDetails->lbl) ? null : \preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\!]/', '_', $fieldDetails->lbl);
74 if ((isset($fieldDetails->mul) || $fieldDetails->typ === 'check') && isset($defaultValues[$fieldKey])) {
75 if (is_array($defaultValues[$fieldKey])) {
76 $fieldDetails->val =
77 wp_json_encode(
78 array_map('sanitize_text_field', $defaultValues[$fieldKey])
79 );
80 } else {
81 $fieldDetails->val = sanitize_text_field($defaultValues[$fieldKey]);
82 }
83 } elseif (isset($defaultValues[$fieldKey])) {
84 $fieldDetails->val = is_string($defaultValues[$fieldKey]) ?
85 sanitize_text_field($defaultValues[$fieldKey]) :
86 sanitize_text_field($defaultValues[$fieldKey][count($defaultValues[$fieldKey]) - 1]);
87 }
88 }
89 return $form_content;
90 }
91
92 public function getFormContent()
93 {
94 $formContent = json_decode(static::$form[0]->form_content);
95 $types = ['check', 'radio', 'select'];
96 $filter = false;
97 foreach ($formContent->fields as $field) {
98 if (in_array($field->typ, $types) && property_exists($field, "customType")) {
99 $filter = true;
100 }
101 }
102 if ($filter == true) {
103 $updateFields = apply_filters('bitform_dynamic_field_filter', $formContent->fields);
104 $formContent->fields = $updateFields;
105 }
106 return $formContent;
107 }
108
109 public function getFormName()
110 {
111 return static::$form[0]->form_name;
112 }
113
114 public function getFields()
115 {
116 if (!is_null($this->_fields)) {
117 return $this->_fields;
118 }
119 $form_content = \json_decode(static::$form[0]->form_content);
120 $layout = $form_content->layout;
121 $fields = $form_content->fields;
122 $field_details = array();
123 foreach ($fields as $key => $field) {
124 if ($field->typ === 'recaptcha') {
125 continue;
126 }
127 // $field_name = empty($field->lbl) ? null : \preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $field->lbl);
128 $field_type = $field->typ;
129 $field_details[$key]['label'] = empty($field->lbl) ? null : $field->lbl;
130 $field_details[$key]['type'] = $field_type;
131 $field_details[$key]['key'] = $key;
132 if (isset($field->customType)) {
133 $field_details[$key]['customType'] = $field->customType;
134 }
135
136 if (isset($field->err)) {
137 if (isset($field->err->entryUnique)) {
138 $field_details[$key]['entryUnique'] = $field->err->entryUnique;
139 }
140 if (isset($field->err->userUnique)) {
141 $field_details[$key]['userUnique'] = $field->err->userUnique;
142 }
143 }
144
145 if (isset($field->mul)) {
146 $field_details[$key]['mul'] = $field->mul;
147 }
148 if ($field_type === 'file-up' && isset($field->exts)) {
149 $field_details[$key]['valid']['type'] = $field->exts;
150 }
151 if (isset($field->valid) && !is_null($field->valid)) {
152 if (isset($field->valid->req)) {
153 $field_details[$key]['valid']['req'] = $field->valid->req;
154 }
155 if (isset($field->valid->reqMsg)) {
156 $field_details[$key]['valid']['reqMsg'] = $field->valid->reqMsg;
157 }
158 if (isset($field->valid->typMsg)) {
159 $field_details[$key]['valid']['typMsg'] = $field->valid->typMsg;
160 }
161 }
162 }
163 if ($this->isGCLIDEnabled()) {
164 $field_details['GCLID']['name'] = 'GCLID';
165 $field_details['GCLID']['adminLbl'] = 'GCLID';
166 $field_details['GCLID']['key'] = 'GCLID';
167 $field_details['GCLID']['type'] = 'hidden';
168 }
169 $this->_fields = $field_details;
170 return $field_details;
171 }
172 public function getFieldsKey()
173 {
174 $form_content = \json_decode(static::$form[0]->form_content);
175 $fields = $form_content->fields;
176 $field_details = array();
177 foreach ($fields as $key => $field) {
178 if ($field->typ === 'recaptcha') {
179 continue;
180 }
181 // $field_name = empty($field->lbl) ? null : \preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $field->lbl);
182 $field_details[$key] = $key;
183 }
184 if ($this->isGCLIDEnabled()) {
185 $field_details['GCLID'] = 'GCLID';
186 }
187 return $field_details;
188 }
189
190 public function getFieldLabel($forQuery = false)
191 {
192 if (!is_null($this->_field_label)) {
193 return $this->_field_label;
194 }
195 $form_content = \json_decode(static::$form[0]->form_content);
196 $fields = $form_content->fields;
197 $field_details = array();
198 $fieldCounter = 0;
199 foreach ($fields as $key => $field) {
200 if ($field->typ === 'recaptcha' || $field->typ === 'html' || $field->typ === 'button') {
201 continue;
202 }
203 $field_details[$fieldCounter]['name'] = empty($field->lbl) ? null : $field->lbl;
204 $field_details[$fieldCounter]['adminLbl'] = empty($field->adminLbl) ? $field_details[$fieldCounter]['name'] : $field->adminLbl;
205 $field_details[$fieldCounter]['key'] = $key;
206 $field_details[$fieldCounter]['type'] = $field->typ;
207 $fieldCounter += 1;
208 }
209 if ($this->isGCLIDEnabled()) {
210 $field_details[$fieldCounter]['name'] = 'GCLID';
211 $field_details[$fieldCounter]['adminLbl'] = 'GCLID';
212 $field_details[$fieldCounter]['key'] = 'GCLID';
213 $field_details[$fieldCounter]['type'] = 'hidden';
214 $fieldCounter += 1;
215 }
216 if (!$forQuery) {
217 $field_details = (array) $this->addEntryInfo($field_details, $fieldCounter);
218 }
219 $this->_field_label = $field_details;
220 return $field_details;
221 }
222
223 public function getUploadFields()
224 {
225 if (!is_null($this->_has_upload)) {
226 return $this->_has_upload;
227 }
228 $upload_fields = array();
229 $form_field_details = $this->getFields();
230 foreach ($form_field_details as $field_name => $__field_detail) {
231 if (isset($__field_detail['type']) && $__field_detail['type'] === 'file-up') {
232 $upload_fields[] = $field_name;
233 }
234 }
235 $this->_has_upload = $upload_fields;
236 return $upload_fields;
237 }
238
239 private function entryInsert($user_details)
240 {
241 $formEntryModel = new FormEntryModel();
242 $entryId = $formEntryModel->insert(
243 array(
244 'form_id' => $this->form_id,
245 'user_id' => $user_details['id'],
246 'user_ip' => $user_details['ip'],
247 'user_device' => $user_details['device'],
248 'referer' => $user_details['page'],
249 'status' => 0,
250 'created_at' => $user_details['time']
251 )
252 );
253 return $entryId;
254 }
255
256 private function submisionLog($user_details, $entry_id, $type)
257 {
258 $formEntryLogModel = new FormEntryLogModel();
259 $logId = $formEntryLogModel->form_log_insert(
260 array(
261 "user_id" => $user_details['id'],
262 "action_type" => $type,
263 "log_type" => "entry",
264 "ip" => $user_details['ip'],
265 "form_entry_id" => $entry_id,
266 "content" => null,
267 "form_id" => $this->form_id,
268 "created_at" => $user_details['time'],
269 )
270 );
271 return $logId;
272 }
273
274 private function isArrayAllKeyInt($InputArray)
275 {
276 if (!is_array($InputArray)) {
277 return false;
278 }
279
280 if (count($InputArray) <= 0) {
281 return true;
282 }
283
284 return array_unique(array_map("is_int", array_keys($InputArray))) === array(true);
285 }
286
287 private function saveEntryMeta($submitted_data, $entry_id)
288 {
289 $errorInEntryMetaInsert = false;
290 $entryMeta = new FormEntryMetaModel();
291 foreach ($submitted_data as $key => $value) {
292 $value = $submitted_data[$key];
293 if (is_string($value)) {
294 $value = wp_unslash($value);
295 } elseif ($this->isArrayAllKeyInt($value)) {
296 $value = wp_json_encode(array_values($value));
297 } else {
298 $value = wp_json_encode($value);
299 }
300 $status = $entryMeta->insert(
301 array(
302 'bitforms_form_entry_id' => $entry_id,
303 'meta_key' => $key,
304 'meta_value' => $value
305 )
306 );
307 if (is_wp_error($status)) {
308 $errorInEntryMetaInsert = true;
309 break;
310 }
311 }
312 return $errorInEntryMetaInsert;
313 }
314
315 public function saveFormEntry($submitted_data)
316 {
317 unset($submitted_data[$this->getFormIdentifier()]);
318 $form_content = \json_decode(static::$form[0]->form_content);
319 do_action('bitform_save_entry', $this, $submitted_data);
320 $key = null;
321 $ipTool = new IpTool();
322 $user_details = $ipTool->getUserDetail();
323 $form_fields = $this->getFields();
324 $submitted_data = $this->passwordEncrypted($submitted_data, $form_fields);
325 global $wpdb;
326 $wpdb->query("START TRANSACTION");
327 $entry_id = $this->entryInsert($user_details);
328 $log_id = null;
329 if (is_wp_error($entry_id)) {
330 return new WP_Error('insert_error', __('Sorry, Error occurred in saving form entry', 'bit-form'));
331 }
332 if ($entry_id) {
333 $log_id = $this->submisionLog($user_details, $entry_id, 'create', $key);
334 if (is_wp_error($log_id)) {
335 $wpdb->query("ROLLBACK");
336 return new WP_Error('error_entry_log', __('Sorry, error occurred in logging form entry', 'bit-form'));
337 }
338 }
339 if ($entry_id) {
340 $submitted_fields = $this->getFormContentWithValue($submitted_data)->fields;
341 $workFlowRunHelper = new WorkFlowRunHelper($this->form_id);
342 $workFlowreturnedOnSubmit = $workFlowRunHelper->executeOnSubmit(
343 'create',
344 $submitted_fields,
345 $submitted_data,
346 $entry_id,
347 $log_id
348 );
349 if (!empty($workFlowreturnedOnSubmit['fields'])) {
350 $submitted_data = $workFlowreturnedOnSubmit['fields'];
351 }
352
353 $file_fields = $this->getUploadFields();
354 $fileHandler = new FileHandler;
355 foreach ($_FILES as $file_name => $file_details) {
356 if ($file_fields && in_array($file_name, $file_fields)) {
357 $filePath = $fileHandler->moveUploadedFiles($file_details, $this->form_id, $entry_id);
358 if (!empty($filePath)) {
359 $submitted_data[$file_name] = $filePath;
360 }
361 }
362 }
363
364 if (!isset($form_content->additional->enabled->submission)) {
365 $errorInEntryMetaInsert = $this->saveEntryMeta($submitted_data, $entry_id);
366 if ($errorInEntryMetaInsert) {
367 $wpdb->query("ROLLBACK");
368 return new WP_Error('insert_error', __('Sorry, Error occured in saving form entry data', 'bit-form'));
369 }
370 }
371 $wpdb->query("COMMIT");
372 $this->setSubmissionCount();
373 $workFlowreturnedOnSubmit['fields'] = $submitted_data;
374
375 return $workFlowreturnedOnSubmit;
376 }
377 }
378
379 public function passwordEncrypted($updatedValue, $form_fields)
380 {
381 $integrationHandler = new IntegrationHandler($this->form_id);
382 $formIntegrations = $integrationHandler->getAllIntegration('wp_user_auth', 'wp_auth', 1);
383 if (!isset($formIntegrations->errors['result_empty'])) {
384 foreach ($form_fields as $field) {
385 if (array_key_exists($field['key'], $updatedValue) && $field['type'] == 'password') {
386 $updatedValue[$field['key']] = '**** (encrypted)';
387 }
388 }
389 }
390 return $updatedValue;
391 }
392
393 public function updateFormEntry($updatedValue, $formID, $entryID)
394 {
395 $formEntryModel = new FormEntryModel();
396 $formEntryLogModel = new FormEntryLogModel();
397 $formOldData = $formEntryLogModel->get_form_value($entryID);
398 $key = null;
399 $entryMeta = new FormEntryMetaModel();
400 $ipTool = new IpTool();
401 $user_details = $ipTool->getUserDetail();
402 $form_fields = $this->getFields();
403 $updatedValue = $this->passwordEncrypted($updatedValue, $form_fields);
404 $field_map = [];
405 foreach ($formOldData as $index => $data) {
406 foreach ($form_fields as $field_key => $field) {
407 if ($data->meta_key == $field['key']) {
408 $field_map[$field_key] = $field['key'];
409 }
410 }
411 }
412 $formFieldValidator = new FormFieldValidator($form_fields, $updatedValue, $_FILES);
413 $validateField = $formFieldValidator->validate('edit', $formID);
414 if (!$validateField) {
415 $errorMessage = count($formFieldValidator->getMessage()) > 0 ?
416 $formFieldValidator->getMessage() : __("Internal error occured!!!", 'bit-form');
417 return new WP_Error('validation_error', $errorMessage);
418 }
419 $formEntry = $formEntryModel->update(
420 array(
421 "user_id" => $user_details['id'],
422 "user_ip" => $user_details['ip'],
423 "user_device" => $user_details['device'],
424 "status" => 0,
425 "updated_at" => $user_details['time']
426 ),
427 array(
428 'form_id' => $formID,
429 'id' => $entryID
430 )
431 );
432 $log_id = null;
433 if ($formEntry) {
434 $log_id = $this->submisionLog($user_details, $entryID, 'update');
435 }
436
437 if (is_wp_error($formEntry) || !$formEntry) {
438 return new WP_Error('empty_form', __('provided form entries does not exists', 'bit-form'));
439 }
440
441 $file_fields = $this->getUploadFields();
442 if (count($file_fields) > 0) {
443 $fileHandler = new FileHandler();
444 foreach ($file_fields as $file_name) {
445 if (isset($updatedValue[$file_name . '_old'])) {
446 $file_exists = $entryMeta->get(
447 'meta_value',
448 array(
449 'bitforms_form_entry_id' => $entryID,
450 'meta_key' => $file_name
451 )
452 );
453 if (!is_wp_error($file_exists) && count($file_exists) > 0) {
454 $files_in_db = json_decode($file_exists[0]->meta_value);
455 $files_old = empty($updatedValue[$file_name . '_old']) ? [] : explode(',', $updatedValue[$file_name . '_old']);
456 $deleted_file = array_diff($files_in_db, $files_old);
457 if (count($deleted_file) > 0) {
458 $fileHandler->deleteFiles($formID, $entryID, $deleted_file);
459 }
460 $updatedValue[$file_name] = wp_json_encode($files_old);
461 }
462 }
463 if (!empty($_FILES[$file_name]['name'])) {
464 $meta_value = $fileHandler->moveUploadedFiles($_FILES[$file_name], $formID, $entryID);
465 if (!empty($meta_value)) {
466 if (isset($updatedValue[$file_name . '_old']) && !is_wp_error($file_exists) && count($file_exists) > 0) {
467 $meta_value = empty($files_old) ? $meta_value : array_merge($meta_value, $files_old);
468 $updatedValue[$file_name] = wp_json_encode($meta_value);
469 } else {
470 $data = array(
471 'bitforms_form_entry_id' => $entryID,
472 'meta_key' => $file_name,
473 'meta_value' => wp_json_encode($meta_value)
474 );
475 $newFileInsertStatus = $entryMeta->insert(
476 $data
477 );
478 $updatedValue[$file_name] = wp_json_encode($meta_value);
479 }
480 }
481 }
482 }
483 }
484
485
486
487 unset($updatedValue['_ajax_nonce']);
488 unset($_REQUEST['g-recaptcha-response']);
489
490 $workFlowRunHelper = new WorkFlowRunHelper($formID);
491 $workFlowreturnedOnSubmit = $workFlowRunHelper->executeOnSubmit(
492 'edit',
493 $this->getFormContentWithValue($updatedValue)->fields,
494 $updatedValue,
495 $entryID,
496 $log_id
497 );
498 if (!empty($workFlowreturnedOnSubmit['fields'])) {
499 $updatedValue = $workFlowreturnedOnSubmit['fields'];
500 }
501
502
503 $toUpdateValues = [];
504 foreach ($form_fields as $field) {
505 if (isset($updatedValue[$field['key']])) {
506 $toUpdateValues[$field['key']] = $updatedValue[$field['key']];
507 }
508 }
509 $formEntryMetaUpdateStatus = $entryMeta->update(
510 $toUpdateValues,
511 array(
512 'bitforms_form_entry_id' => $entryID
513 )
514 );
515 if (is_wp_error($formEntryMetaUpdateStatus) || isset($newFileInsertStatus) && is_wp_error($newFileInsertStatus)) {
516 return $formEntryMetaUpdateStatus;
517 }
518 $toUpdateValues = array_merge($formEntryMetaUpdateStatus, array('entry_id' => $entryID));
519 if (empty($workFlowreturnedOnSubmit['message'])) {
520 $workFlowreturnedOnSubmit['message'] = __('Entry Updated Successfully', 'bit-form');
521 }
522 $customFieldHandler = new CustomFieldHandler();
523 $toUpdateValues = $customFieldHandler->updatedData($form_fields, $toUpdateValues);
524 $workFlowreturnedOnSubmit['updatedData'] = $toUpdateValues;
525 $counter = 0;
526 for ($i = 0; $i < count($formOldData); $i++) {
527 if (array_key_exists($formOldData[$i]->meta_key . '_old', $toUpdateValues)) {
528 unset($toUpdateValues[$formOldData[$i]->meta_key . '_old']);
529 }
530 if (in_array($formOldData[$i]->meta_key, $file_fields)) {
531 if (
532 empty($_FILES[$formOldData[$i]->meta_key]['name'])
533 || (is_array($_FILES[$formOldData[$i]->meta_key]['name'])
534 && count($_FILES[$formOldData[$i]->meta_key]['name']) === 1
535 && empty($_FILES[$formOldData[$i]->meta_key]['name'][0]))
536 ) {
537 unset($toUpdateValues[$formOldData[$i]->meta_key]);
538 continue;
539 }
540 if (is_array($_FILES[$formOldData[$i]->meta_key]['name']) && !in_array($_FILES[$formOldData[$i]->meta_key]['name'], json_decode($formOldData[$i]->meta_value))) {
541 $key[$i] = '${' . $formOldData[$i]->meta_key . '} file was Updated To ' . json_encode($_FILES[$formOldData[$i]->meta_key]['name']);
542 } elseif (!is_array($_FILES[$formOldData[$i]->meta_key]['name']) && !in_array($_FILES[$formOldData[$i]->meta_key]['name'], json_decode($formOldData[$i]->meta_value))) {
543 $key[$i] = '${' . $formOldData[$i]->meta_key . '} file was Updated To ' . $_FILES[$formOldData[$i]->meta_key]['name'];
544 }
545 unset($toUpdateValues[$formOldData[$i]->meta_key]);
546 } elseif (isset($toUpdateValues[$formOldData[$i]->meta_key])) {
547 if (is_array($toUpdateValues[$formOldData[$i]->meta_key])) {
548 if (json_decode($formOldData[$i]->meta_value) !== $toUpdateValues[$formOldData[$i]->meta_key]) {
549 $key[$i] = '${' . $formOldData[$i]->meta_key . '} was Updated From ' . implode(',', json_decode($formOldData[$i]->meta_value)) . ' To ' . implode(",", $toUpdateValues[$formOldData[$i]->meta_key]);
550 }
551 } elseif (is_string($toUpdateValues[$formOldData[$i]->meta_key]) && !FieldValueHandler::isEmpty($toUpdateValues[$formOldData[$i]->meta_key])) {
552 if ($formOldData[$i]->meta_value !== $toUpdateValues[$formOldData[$i]->meta_key]) {
553 $key[$i] = '${' . $formOldData[$i]->meta_key . '} was Updated' . ($formOldData[$i]->meta_value ? ' From ' . $formOldData[$i]->meta_value : '') . ' To ' . $toUpdateValues[$formOldData[$i]->meta_key];
554 }
555 }
556 }
557 $counter++;
558 }
559
560 $newField = array_keys(array_diff_key($formEntryMetaUpdateStatus, $field_map));
561 for ($i = 0; $i < count($newField); $i++) {
562 if (is_array($toUpdateValues[$newField[$i]]) && !empty($toUpdateValues[$newField[$i]])) {
563 $key[$counter + $i] = '${' . $newField[$i] . '} Updated To ' . implode(",", $toUpdateValues[$newField[$i]]);
564 } elseif (is_string($newField[$i]) && !FieldValueHandler::isEmpty($toUpdateValues[$newField[$i]])) {
565 $key[$counter + $i] = '${' . $newField[$i] . '} Updated To ' . $toUpdateValues[$newField[$i]];
566 }
567 }
568 if ($key !== null) {
569 $logUpdate = implode("b::f", (array) $key);
570 $formEntryLogUpdate = $formEntryLogModel->logUpdate($logUpdate, $log_id);
571 }
572 return $workFlowreturnedOnSubmit;
573 }
574
575 public function setSubmissionCount($countStep = 1)
576 {
577 $update_status = $this->formModel->update(
578 array(
579 'entries' => intval(static::$form[0]->entries) + $countStep
580 ),
581 array(
582 'id' => $this->form_id
583 )
584 );
585 }
586 public function resetSubmissionCount($countStep)
587 {
588 $update_status = $this->formModel->update(
589 array(
590 'entries' => intval($countStep)
591 ),
592 array(
593 'id' => $this->form_id
594 )
595 );
596 }
597
598 public function getCaptchaSettings()
599 {
600 $formContents = $this->getFormContent();
601 $fieldStr = wp_json_encode($formContents->fields);
602 if (strpos($fieldStr, '"typ":"recaptcha"') !== false) {
603 return true;
604 }
605 }
606 public function getCaptchaV3Settings()
607 {
608 $formContents = $this->getFormContent();
609 if (!empty($formContents->additional->enabled) && !empty($formContents->additional->enabled->recaptchav3)) {
610 return $formContents->additional->settings->recaptchav3;
611 }
612 return false;
613 }
614
615 public function isGCLIDEnabled()
616 {
617 $formContents = $this->getFormContent();
618 if (isset($formContents->additional->enabled->captureGCLID) && $formContents->additional->enabled->captureGCLID) {
619 return true;
620 }
621 return false;
622 }
623
624 protected function addEntryInfo($field_details, $counter)
625 {
626 $infos = [
627 '__user_id' => __('User', 'bit-form'),
628 '__user_ip' => __('IP address', 'bit-form'),
629 //'__user_location' => __(''),
630 '__referer' => __('Refer URL', 'bit-form'),
631 '__user_device' => __('Device', 'bit-form'),
632 '__created_at' => __('Created Time', 'bit-form'),
633 '__updated_at' => __('Modified Time', 'bit-form'),
634 ];
635 foreach ($infos as $key => $value) {
636 $field_details[$counter]['name'] = $value;
637 $field_details[$counter]['key'] = $key;
638 $field_details[$counter]['type'] = 'sys';
639 $counter = $counter + 1;
640 }
641
642 return $field_details;
643 }
644 }
645