PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.3.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.3.2
V3.3.2 3.3.1 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 All 139 releases
← All changes | includes/Admin/Form/AdminFormHandler.php +260 -46 3.1.1 → V3.3.2 View file →
@@ -13,15 +13,14 @@
13 13 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
14 14 use BitCode\BitForm\Core\Database\FormEntryModel;
15 15 use BitCode\BitForm\Core\Database\FormModel;
16 16 use BitCode\BitForm\Core\Database\IntegrationModel;
17 -use BitCode\BitForm\Core\Database\PdfTemplateModel;
18 17 use BitCode\BitForm\Core\Database\ReportsModel;
19 18 use BitCode\BitForm\Core\Database\SuccessMessageModel;
20 19 use BitCode\BitForm\Core\Database\WorkFlowModel;
20 +use BitCode\BitForm\Core\Form\FormManager;
21 21 use BitCode\BitForm\Core\Integration\IntegrationHandler;
22 22 use BitCode\BitForm\Core\Messages\EmailTemplateHandler;
23 -use BitCode\BitForm\Core\Messages\PdfTemplateHandler;
24 23 use BitCode\BitForm\Core\Messages\SuccessMessageHandler;
25 24 use BitCode\BitForm\Core\Migration\MigrationHelper;
26 25 use BitCode\BitForm\Core\Util\FileHandler;
27 26 use BitCode\BitForm\Core\Util\FormDuplicateHelper;
@@ -87,9 +86,9 @@
87 86 $sm_width = 400;
88 87 $lg_styles = '';
89 88 $md_styles = '';
90 89 $sm_styles = '';
91 - for ($i = 0; $i < count($layout->lg); $i++) {
90 + for ($i = 0; $i < count($layout->lg ?? []); $i++) {
92 91 $fld = $layout->lg[$i];
93 92
94 93 if ($fld->w < 10) {
95 94 $lay_row_height = 43;
@@ -241,8 +240,13 @@
241 240 'empty_form',
242 241 __('Form Name Should Be Within 50 Characters', 'bit-form')
243 242 );
244 243 }
244 + // Guard: never persist orphan fields (in fields but in no layout) — they
245 + // render nothing yet their validation rules block submission. Covers old
246 + // clients and hand-edited imports (importAForm funnels through here).
247 + $this->pruneOrphanFields($fields, $nestedLayout, $layout, null, $post);
248 + FormManager::syncCompositeChildNames($fields);
245 249 $form_content = [
246 250 'fields' => $fields,
247 251 'layout' => $layout,
248 252 'nestedLayout' => $nestedLayout,
@@ -321,8 +325,11 @@
321 325 $savedID = $successMessageHandler->saveMessage($messageDetail);
322 326 if ($savedID) {
323 327 $msgIdx = empty($messageDetail->id) ? $messageKey : wp_json_encode(['id' => $messageDetail->id]);
324 328 $integartionIDForWorkflow['successMsg'][$msgIdx] = $savedID;
329 + if (!empty($messageDetail->clRef)) {
330 + $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
331 + }
325 332 $messageDetail->id = $savedID;
326 333 $style = $this->updateSuccessMessageClassName($style, $messageKey, $savedID);
327 334 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
328 335 }
@@ -355,11 +362,17 @@
355 362 $emailTemplateHandler
356 363 = new EmailTemplateHandler($formID, $user_details);
357 364 foreach ($mailTem as $templateKey => $templateDetail) {
358 365 $savedID = $emailTemplateHandler->saveTemplate($templateDetail);
359 - if ($savedID) {
366 + if ($savedID && !is_wp_error($savedID)) {
360 367 $tempIdx = empty($templateDetail->id) ? $templateKey : wp_json_encode(['id' => $templateDetail->id]);
361 368 $integartionIDForWorkflow['mailNotify'][$tempIdx] = $savedID;
369 + if (!empty($templateDetail->clRef)) {
370 + $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
371 + }
372 + // return the new id (and drop the temp ref) so the frontend reconciles the template
373 + $templateDetail->id = $savedID;
374 + unset($templateDetail->clRef);
362 375 }
363 376 }
364 377 }
365 378 // Email Template [end] */
@@ -364,10 +377,10 @@
364 377 }
365 378 // Email Template [end] */
366 379
367 380 // PDF Template [start]
368 - if (!empty($pdfTem)) {
369 - $pdfTemplateHandler = new PdfTemplateHandler($formID);
381 + if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
382 + $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
370 383 $workFlowString = '';
371 384 if (!empty($workFlows)) {
372 385 $workFlowString = wp_json_encode($workFlows);
373 386 }
@@ -380,8 +393,17 @@
380 393 $this->pdfFontDownload($pdfSetting->font->name);
381 394 }
382 395 if (!empty($workFlowString)) {
383 396 $workFlowString = str_replace('"pdfId":"{\"id\":\"' . $templateDetail->id . '\"}"', '"pdfId":"{\"id\":\"' . $savedID . '\"}"', $workFlowString);
397 + // Multi-PDF: remap ids inside "pdfIds":[...] segments only — email-template ids use
398 + // the same {\"id\":N} token shape, so a global replace would corrupt them.
399 + $workFlowString = preg_replace_callback(
400 + '/"pdfIds":\[[^\]]*\]/',
401 + function ($matches) use ($templateDetail, $savedID) {
402 + return str_replace('{\"id\":\"' . $templateDetail->id . '\"}', '{\"id\":\"' . $savedID . '\"}', $matches[0]);
403 + },
404 + $workFlowString
405 + );
384 406 }
385 407 }
386 408 if (!empty($workFlowString) && !empty($workFlows)) {
387 409 $workFlows = json_decode($workFlowString);
@@ -393,8 +415,14 @@
393 415 if (!empty($formSettings->confirmation->type)) {
394 416 $allIntegrations = $formSettings->confirmation->type;
395 417 foreach ($allIntegrations as $integrationType => $integrationGroup) {
396 418 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
419 + $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
420 + // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
421 + $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
422 + if (is_object($singleIntegrationDetail)) {
423 + unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
424 + }
397 425 if (empty($singleIntegrationDetail->details)) {
398 426 $integrationName = $singleIntegrationDetail->title;
399 427 unset($singleIntegrationDetail->title, $singleIntegrationDetail->id);
400 428
@@ -404,11 +432,14 @@
404 432 $integrationName = $singleIntegrationDetail->title;
405 433 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
406 434 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
407 435 }
408 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
436 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
409 437 $integIdx = empty($singleIntegrationDetail->id) ? $savedID : wp_json_encode(['id' => $singleIntegrationDetail->id]);
410 438 $integartionIDForWorkflow[$integrationType][$integIdx] = $savedID;
439 + if (!empty($clRef) && 'redirectPage' === $integrationType) {
440 + $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
441 + }
411 442 }
412 443 }
413 444 }
414 445 if (isset($formSettings->formAbandonment)) {
@@ -426,8 +457,11 @@
426 457 $integrationType = $singleIntegrationDetail->type;
427 458 unset($singleIntegrationDetail->type);
428 459 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
429 460 unset($singleIntegrationDetail->id);
461 + // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
462 + $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
463 + unset($singleIntegrationDetail->__bf_cl_ref);
430 464 if (empty($singleIntegrationDetail->details)) {
431 465 $integrationDetails = !is_string($singleIntegrationDetail) ?
432 466 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
433 467 } else {
@@ -436,8 +470,11 @@
436 470 }
437 471 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
438 472 $integIdx = empty($singleIntegrationDetailID) ? $singleIntegrationKey : wp_json_encode(['id' => $singleIntegrationDetailID]);
439 473 $integartionIDForWorkflow['integ'][$integIdx] = $savedID;
474 + if (!empty($clRef) && !is_wp_error($savedID)) {
475 + $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
476 + }
440 477 }
441 478 }
442 479 //Integrations [end]
443 480 //wrokFlows [start]
@@ -488,8 +525,12 @@
488 525 $updated_data['form_content']['is_default'] = 1;
489 526 }
490 527 $updated_data['message'] = __('Form Saved successfully', 'bit-form');
491 528
529 + // Form and dependent rows are persisted; multilingual providers register
530 + // the form's translatable strings here.
531 + do_action('bitform_form_saved', $save_status);
532 +
492 533 return $updated_data;
493 534 }
494 535 }
495 536
@@ -546,8 +587,12 @@
546 587 if (empty($fields) || empty($layout) || is_null($formID)) {
547 588 return new WP_Error('empty_form', 'Can not update empty form.');
548 589 }
549 590
591 + // Guard: never persist orphan fields (see createNewForm). Fail closed.
592 + $this->pruneOrphanFields($fields, $nestedLayout, $layout, $formID, $post);
593 + FormManager::syncCompositeChildNames($fields);
594 +
550 595 $form_content = [
551 596 'fields' => $fields,
552 597 'layout' => $layout,
553 598 'nestedLayout' => $nestedLayout,
@@ -588,8 +633,11 @@
588 633 $savedID = $successMessageHandler->saveMessage($messageDetail);
589 634 if ($savedID) {
590 635 $newData['settingConfiramation'] = 1;
591 636 $integartionIDForWorkflow['successMsg'][$messageKey] = $savedID;
637 + if (!empty($messageDetail->clRef)) {
638 + $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
639 + }
592 640 $messageDetail->id = $savedID;
593 641 $builder_helper_state->style = $this->updateSuccessMessageClassName($builder_helper_state->style, $messageKey, $savedID);
594 642 if (isset($atomic_class_map)) {
595 643 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
@@ -614,18 +662,29 @@
614 662 $newData['mailTemplate'] = 2;
615 663 } else {
616 664 $newData['mailTemplate'] = 1;
617 665 $integartionIDForWorkflow['mailTem'][$templateKey] = $savedID;
666 + if (!empty($templateDetail->clRef)) {
667 + $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
668 + }
669 + // return the new id (and drop the temp ref) so the frontend reconciles the template
670 + $templateDetail->id = $savedID;
671 + unset($templateDetail->clRef);
618 672 }
619 673 } else {
620 - $emailTemplateHandler->updateTemplate($templateDetail);
674 + $updated = $emailTemplateHandler->updateTemplate($templateDetail);
675 + if (is_wp_error($updated) && 'db_error' === $updated->get_error_code()) {
676 + $newData['mailTemplate'] = 2;
677 + } elseif (0 === $newData['mailTemplate']) {
678 + $newData['mailTemplate'] = 1;
679 + }
621 680 }
622 681 }
623 682 }
624 683 // return $formSettings;
625 684 // Email Template [end] */
626 - if (!empty($pdfTem)) {
627 - $pdfTemplateHandler = new PdfTemplateHandler($formID);
685 + if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
686 + $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
628 687
629 688 foreach ($pdfTem as $templateKey => $templateDetail) {
630 689 if (isset($templateDetail->setting->font->name)) {
631 690 $this->pdfFontDownload($templateDetail->setting->font->name);
@@ -645,8 +704,15 @@
645 704 if (!empty($formSettings->confirmation->type)) {
646 705 $allIntegrations = $formSettings->confirmation->type;
647 706 foreach ($allIntegrations as $integrationType => $integrationGroup) {
648 707 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
708 + // Redirect (and webhook) enable/disable toggle persists to the integration status column.
709 + $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
710 + // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
711 + $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
712 + if (is_object($singleIntegrationDetail)) {
713 + unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
714 + }
649 715 if (empty($singleIntegrationDetail->details)) {
650 716 $integrationName = $singleIntegrationDetail->title;
651 717 unset($singleIntegrationDetail->title);
652 718 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
@@ -660,13 +726,16 @@
660 726 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
661 727 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
662 728 }
663 729 if (empty($singleIntegrationDetailID)) {
664 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
730 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
665 731 $newData['settingConfiramation'] = 1;
666 732 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
733 + if (!empty($clRef) && 'redirectPage' === $integrationType) {
734 + $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
735 + }
667 736 } else {
668 - $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form');
737 + $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
669 738 }
670 739 }
671 740 }
672 741 }
@@ -677,8 +746,11 @@
677 746 $integrationType = $singleIntegrationDetail->type;
678 747 unset($singleIntegrationDetail->type);
679 748 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
680 749 unset($singleIntegrationDetail->id);
750 + // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
751 + $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
752 + unset($singleIntegrationDetail->__bf_cl_ref);
681 753 if (empty($singleIntegrationDetail->details)) {
682 754 $integrationDetails = !is_string($singleIntegrationDetail) ?
683 755 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
684 756 } else {
@@ -687,8 +759,11 @@
687 759 }
688 760 if (empty($singleIntegrationDetailID)) {
689 761 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
690 762 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
763 + if (!empty($clRef) && !is_wp_error($savedID)) {
764 + $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
765 + }
691 766 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
692 767 $newData['integation'] = 2;
693 768 } else {
694 769 $newData['integation'] = 1;
@@ -728,8 +803,11 @@
728 803 }
729 804 $form_content = array_merge($form_content, ['workFlowExist' => $workFlowExist]);
730 805 //wrokFlows [end]
731 806 //reports [start] */
807 + // read unconditionally after the reports block; a save without currentReport
808 + // must not trip an undefined-variable warning
809 + $reportIsDefault = null;
732 810 if (!empty($reports)) {
733 811 $reportsModel = new ReportsModel();
734 812 $fieldNames = [];
735 813 foreach ($fields as $key => $field) {
@@ -747,9 +825,13 @@
747 825 $fieldNames['__created_at'] = __('Created Time', 'bit-form');
748 826 $fieldNames['__updated_at'] = __('Modified Time', 'bit-form');
749 827
750 828 $reportIsDefault = null;
751 - if (isset($form_content['report_id'])) {
829 + // The client posts currentReport as {} whenever its report atom has not resolved yet. That
830 + // is an empty stdClass, which empty() above treats as non-empty, so we reach here with
831 + // nothing to save — and writing the validated result would replace the stored report's
832 + // column order, hidden columns, page size and name with an empty list. Leave the row alone.
833 + if (isset($form_content['report_id']) && ReportsModel::isValidatableReport($reports)) {
752 834 $validDateReport = $reportsModel->validateReportFields($reports, $fieldNames);
753 835 if (isset($reports->isDefault)) {
754 836 $reportIsDefault = $reports->isDefault;
755 837 } else {
@@ -860,8 +942,12 @@
860 942 }
861 943 if (2 === $newData['reports']) {
862 944 $errorIN .= empty($errorIN) ? 'reports' : ', reports';
863 945 }
946 + // See createNewForm(). Fired before the partial-failure return: the rows
947 + // that did save are already persisted, so their strings still need registering.
948 + do_action('bitform_form_saved', $formId);
949 +
864 950 if (!empty($errorIN)) {
865 951 /* translators: %s: comma-separated list of areas where error occurred */
866 952 $updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bit-form'), $errorIN);
867 953 return new WP_Error('Form update Error.', $updated_data);
@@ -869,12 +955,59 @@
869 955 if (null !== $reportIsDefault) {
870 956 $updated_data['form_content']['is_default'] = $reportIsDefault;
871 957 }
872 958 $updated_data['message'] = __('Form updated successfully.', 'bit-form');
959 +
873 960 return $updated_data;
874 961 }
875 962 }
876 963
964 + /**
965 + * Drop orphan fields (present in `fields` but in no layout) from form_content
966 + * before persisting, and remove now-childless nestedLayout entries.
967 + *
968 + * Entry meta is NEVER touched here — only explicit user deletes clear meta
969 + * (see setEmptyMetaValue). Fail closed: an unusable/partial layout, or a
970 + * client that flagged a failed pre-save layout sync (->skipOrphanPrune),
971 + * prunes nothing. Pruned keys are logged, never silently dropped.
972 + *
973 + * @param object|array $fields by ref; orphan keys removed
974 + * @param object|null $nestedLayout by ref; stale container entries removed
975 + * @param array|object $layout raw layout (single or multi-step)
976 + * @param int|string|null $formID for logging ('new' when absent)
977 + * @param object $post raw request; honors ->skipOrphanPrune
978 + */
979 + private function pruneOrphanFields(&$fields, &$nestedLayout, $layout, $formID, $post)
980 + {
981 + $formLabel = $formID ? $formID : 'new';
982 + if (isset($post->skipOrphanPrune) && $post->skipOrphanPrune) {
983 + Log::debug_log('Bit Form: orphan prune skipped (client reported failed layout sync). FormID=' . $formLabel);
984 + return;
985 + }
986 + $orphanFldKeys = FormManager::computeOrphanFieldKeys($layout, $nestedLayout, $fields);
987 + // null = unusable/partial layout (fail closed); [] = nothing to prune
988 + if (!is_array($orphanFldKeys) || empty($orphanFldKeys)) {
989 + return;
990 + }
991 + Log::debug_log('Bit Form: pruning orphan fields (absent from every layout). FormID=' . $formLabel . ' keys=' . implode(',', $orphanFldKeys));
992 + foreach ($orphanFldKeys as $orphanKey) {
993 + if (is_object($fields)) {
994 + unset($fields->{$orphanKey});
995 + } elseif (is_array($fields)) {
996 + unset($fields[$orphanKey]);
997 + }
998 + }
999 + // prune stale nestedLayout entries — containers that no longer exist in fields
1000 + if (is_object($nestedLayout)) {
1001 + foreach (array_keys(get_object_vars($nestedLayout)) as $nKey) {
1002 + $parentExists = is_object($fields) ? isset($fields->{$nKey}) : isset($fields[$nKey]);
1003 + if (!$parentExists) {
1004 + unset($nestedLayout->{$nKey});
1005 + }
1006 + }
1007 + }
1008 + }
1009 +
877 1010 public function setEmptyMetaValue($fieldkeys)
878 1011 {
879 1012 global $wpdb;
880 1013 // Placeholders and arguments built dynamically from $fieldkeys; count matches at runtime.
@@ -1002,9 +1135,9 @@
1002 1135 'nestedLayout' => !empty($form_content->nestedLayout) ? $form_content->nestedLayout : (object) [],
1003 1136 'formInfo' => !empty($form_content->formInfo) ? $form_content->formInfo : (object) ['formName' => $formManager->getFormName()],
1004 1137 'fields' => $form_content->fields,
1005 1138 'form_name' => $formManager->getFormName(),
1006 - 'workFlowExist' => $form_content->workFlowExist,
1139 + 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1007 1140 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1008 1141 ];
1009 1142 $successMessageHandler
1010 1143 = new SuccessMessageHandler($formID);
@@ -1027,28 +1160,37 @@
1027 1160 if (!is_wp_error($emailTemplates)) {
1028 1161 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1029 1162 $mailTem[] =
1030 1163 [
1031 - 'id' => $emailTemplatevalue->id,
1032 - 'title' => $emailTemplatevalue->title,
1033 - 'sub' => $emailTemplatevalue->sub,
1034 - 'body' => $emailTemplatevalue->body,
1164 + 'id' => $emailTemplatevalue->id,
1165 + 'title' => $emailTemplatevalue->title,
1166 + 'sub' => $emailTemplatevalue->sub,
1167 + 'body' => $emailTemplatevalue->body,
1168 + 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1169 + 'config' => EmailTemplateHandler::normalizeConfig($emailTemplatevalue->config ?? null),
1035 1170 ];
1036 1171 }
1037 1172 }
1038 1173 // get all pdf template
1039 - $pdfTemplateHandler = new PdfTemplateHandler($formID);
1040 - $pdfTemplates = $pdfTemplateHandler->getAll();
1174 + if (class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
1175 + $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
1176 + $pdfTemplates = $pdfTemplateHandler->getAll();
1041 1177
1042 - if (!is_wp_error($pdfTemplates)) {
1043 - foreach ($pdfTemplates as $value) {
1044 - $pdfTem[] =
1045 - [
1046 - 'id' => $value->id,
1047 - 'title' => $value->title,
1048 - 'setting' => json_decode($value->setting),
1049 - 'body' => $value->body,
1050 - ];
1178 + if (!is_wp_error($pdfTemplates)) {
1179 + foreach ($pdfTemplates as $value) {
1180 + $pdfTem[] =
1181 + [
1182 + 'id' => $value->id,
1183 + 'title' => $value->title,
1184 + 'setting' => json_decode($value->setting),
1185 + 'pdf_config' => !empty($value->pdf_config) ? json_decode($value->pdf_config) : (object) [
1186 + 'status' => 1,
1187 + 'header' => '',
1188 + 'footer' => '',
1189 + ],
1190 + 'body' => $value->body,
1191 + ];
1192 + }
1051 1193 }
1052 1194 }
1053 1195
1054 1196 $integrationHandler = new IntegrationHandler($formID);
@@ -1056,10 +1198,11 @@
1056 1198 if (!is_wp_error($formIntegrations)) {
1057 1199 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1058 1200 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1059 1201 $integrationData = [
1060 - 'id' => $integrationValue->id,
1061 - 'title' => $integrationValue->integration_name,
1202 + 'id' => $integrationValue->id,
1203 + 'title' => $integrationValue->integration_name,
1204 + 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1062 1205 ];
1063 1206 if (!empty($integrationValue->integration_details)) {
1064 1207 $integration_details = (array) json_decode($integrationValue->integration_details);
1065 1208 $integrationData = array_merge($integration_details, $integrationData);
@@ -1290,9 +1433,9 @@
1290 1433 $form_content_arr = [
1291 1434 'layout' => $form_content->layout,
1292 1435 'fields' => $form_content->fields,
1293 1436 'form_name' => $formManager->getFormName(),
1294 - 'workFlowExist' => $form_content->workFlowExist,
1437 + 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1295 1438 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1296 1439 ];
1297 1440 $successMessageHandler
1298 1441 = new SuccessMessageHandler($formID);
@@ -1300,11 +1443,12 @@
1300 1443 if (!is_wp_error($successMessages)) {
1301 1444 foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1302 1445 $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1303 1446 [
1304 - 'id' => $sucessMessagevalue->id,
1305 - 'title' => $sucessMessagevalue->message_title,
1306 - 'msg' => $sucessMessagevalue->message_content,
1447 + 'id' => $sucessMessagevalue->id,
1448 + 'title' => $sucessMessagevalue->message_title,
1449 + 'msg' => $sucessMessagevalue->message_content,
1450 + 'config' => !empty($sucessMessagevalue->message_config) ? json_decode($sucessMessagevalue->message_config) : (object) [],
1307 1451 ];
1308 1452 }
1309 1453 }
1310 1454 $emailTemplateHandler
@@ -1313,12 +1457,14 @@
1313 1457 if (!is_wp_error($emailTemplates)) {
1314 1458 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1315 1459 $mailTem[] =
1316 1460 [
1317 - 'id' => $emailTemplatevalue->id,
1318 - 'title' => $emailTemplatevalue->title,
1319 - 'sub' => $emailTemplatevalue->sub,
1320 - 'body' => $emailTemplatevalue->body,
1461 + 'id' => $emailTemplatevalue->id,
1462 + 'title' => $emailTemplatevalue->title,
1463 + 'sub' => $emailTemplatevalue->sub,
1464 + 'body' => $emailTemplatevalue->body,
1465 + 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1466 + 'config' => EmailTemplateHandler::normalizeConfig($emailTemplatevalue->config ?? null),
1321 1467 ];
1322 1468 }
1323 1469 }
1324 1470 $integrationHandler = new IntegrationHandler($formID);
@@ -1326,10 +1472,11 @@
1326 1472 if (!is_wp_error($formIntegrations)) {
1327 1473 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1328 1474 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1329 1475 $integrationData = [
1330 - 'id' => $integrationValue->id,
1331 - 'title' => $integrationValue->integration_name,
1476 + 'id' => $integrationValue->id,
1477 + 'title' => $integrationValue->integration_name,
1478 + 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1332 1479 ];
1333 1480 if (!empty($integrationValue->integration_details)) {
1334 1481 // var_dump(json_decode($integrationValue->integration_details));
1335 1482 $integration_details = (array) json_decode($integrationValue->integration_details);
@@ -1514,10 +1661,12 @@
1514 1661
1515 1662 $emailTemplateModel = new EmailTemplateModel();
1516 1663 $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]);
1517 1664
1518 - $pdfTemplateModel = new PdfTemplateModel();
1519 - $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1665 + if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1666 + $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1667 + $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1668 + }
1520 1669
1521 1670 $integrationModel = new IntegrationModel();
1522 1671 $deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]);
1523 1672
@@ -1607,10 +1756,12 @@
1607 1756
1608 1757 $emailTemplateModel = new EmailTemplateModel();
1609 1758 $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]);
1610 1759
1611 - $pdfTemplateModel = new PdfTemplateModel();
1612 - $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1760 + if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1761 + $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1762 + $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1763 + }
1613 1764
1614 1765 $integrationModel = new IntegrationModel();
1615 1766 $deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]);
1616 1767
@@ -1891,8 +2042,65 @@
1891 2042 $response['fieldDetails'] = $labels;
1892 2043 return $response;
1893 2044 }
1894 2045
2046 + /**
2047 + * Sanitize a request-supplied entry query condition before it reaches the Model
2048 + * layer. Only known entry-table columns are allowed as condition keys, operators
2049 + * are restricted to a safe allow-list ['form_id' => $id] when nothing valid remains.
2050 + *
2051 + * @param mixed $queryCondition
2052 + * @param int $id
2053 + * @return array
2054 + */
2055 + private function sanitizeEntryQueryCondition($queryCondition, $id)
2056 + {
2057 + $allowedColumns = [
2058 + 'id', 'form_id', 'status', 'created_at', 'updated_at',
2059 + 'user_id', 'user_ip', 'user_device', 'user_location', 'referer',
2060 + ];
2061 + $allowedOperators = ['=', '!=', '<>', '<', '>', '<=', '>=', 'LIKE', 'IN'];
2062 +
2063 + if (!is_array($queryCondition)) {
2064 + return ['form_id' => $id];
2065 + }
2066 +
2067 + $safe = [];
2068 + foreach ($queryCondition as $key => $value) {
2069 + if (!in_array($key, $allowedColumns, true)) {
2070 + continue;
2071 + }
2072 +
2073 + if (is_array($value)) {
2074 + // Never honour a request-supplied raw SQL fragment.
2075 + unset($value['raw']);
2076 +
2077 + if (array_key_exists('operator', $value) || array_key_exists('value', $value)) {
2078 + $operator = isset($value['operator']) && is_string($value['operator'])
2079 + ? strtoupper(trim($value['operator']))
2080 + : '=';
2081 + if (!in_array($operator, $allowedOperators, true)) {
2082 + $operator = '=';
2083 + }
2084 + $condValue = isset($value['value']) ? $value['value'] : '';
2085 + if (is_scalar($condValue)) {
2086 + $safe[$key] = ['operator' => $operator, 'value' => $condValue];
2087 + }
2088 + } else {
2089 + // IN-style list: keep scalar members only (bound by the Model).
2090 + $list = array_values(array_filter($value, 'is_scalar'));
2091 + if (!empty($list)) {
2092 + $safe[$key] = $list;
2093 + }
2094 + }
2095 + } elseif (is_scalar($value)) {
2096 + $safe[$key] = $value;
2097 + }
2098 + }
2099 +
2100 + return empty($safe) ? ['form_id' => $id] : $safe;
2101 + }
2102 +
1895 2103 public function getFormEntry($Request, $post)
1896 2104 {
1897 2105 if (!empty($Request['id'])) {
1898 2106 $id = absint(wp_unslash($Request['id']));
@@ -1912,8 +2120,9 @@
1912 2120 $pageSize = isset($post->pageSize) ?
1913 2121 wp_unslash($post->pageSize) : 10;
1914 2122 $queryCondition = isset($post->queryCondition) ? wp_unslash($post->queryCondition) : ['form_id' => $id];
1915 2123 }
2124 + $queryCondition = $this->sanitizeEntryQueryCondition($queryCondition, $id);
1916 2125 if (is_null($id)) {
1917 2126 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1918 2127 }
1919 2128 $formManager = new AdminFormManager($id);
@@ -2282,10 +2491,15 @@
2282 2491 $layout = $formContent->layout;
2283 2492 foreach ($form_fields as $key => $value) {
2284 2493 // $field_name = preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\!]/', '_', $value->lbl);
2285 2494 if (isset($entries[$key])) {
2286 - $form_fields->{$key}->val = $entries[$key];
2495 + $isPassword = isset($value->typ) && 'password' === $value->typ;
2496 + // Never hand a stored password back to the browser; blank keeps it on update.
2497 + $form_fields->{$key}->val = $isPassword ? '' : $entries[$key];
2287 2498 $form_fields->{$key}->name = $key;
2499 + if ($isPassword && '' !== (string) $entries[$key] && isset($value->valid) && is_object($value->valid)) {
2500 + $form_fields->{$key}->valid->req = false;
2501 + }
2288 2502 }
2289 2503 }
2290 2504 $workFlowRunHelper = new WorkFlow($formID);
2291 2505 $workFlowreturnedOnLoad = $workFlowRunHelper->executeOnLoad(