PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
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/Frontend/Form/FrontendFormHandler.php +80 -199 3.2.0 → 2.15.3 View file →
@@ -1,13 +1,8 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Frontend\Form;
4 4
5 -if (!defined('ABSPATH')) {
6 - exit;
7 -}
8 -
9 -use BitCode\BitForm\Admin\Form\AdminFormHandler;
10 5 use BitCode\BitForm\Admin\Form\FrontEndScriptGenerator;
11 6 use BitCode\BitForm\Admin\Form\Helpers;
12 7 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
13 8 use BitCode\BitForm\Core\Database\FormModel;
@@ -12,16 +7,15 @@
12 7 use BitCode\BitForm\Core\Database\FormEntryMetaModel;
13 8 use BitCode\BitForm\Core\Database\FormModel;
14 9 use BitCode\BitForm\Core\Form\FormManager;
15 10 use BitCode\BitForm\Core\Integration\IntegrationHandler;
16 -use BitCode\BitForm\Core\Util\EscapingHelper;
17 11 use BitCode\BitForm\Core\Util\FieldValueHandler;
18 12 use BitCode\BitForm\Core\Util\FileDownloadProvider;
19 13 use BitCode\BitForm\Core\Util\FrontendHelpers;
20 -use BitCode\BitForm\Core\Util\SmartTagRegistry;
21 14 use BitCode\BitForm\Core\Util\SmartTags;
22 15 use BitCode\BitForm\Core\Util\Utilities;
23 16 use BitCode\BitForm\Core\WorkFlow\WorkFlow;
17 +use BitCode\BitFormPro\Admin\FormSettings\FormAbandonment;
24 18
25 19 final class FrontendFormHandler
26 20 {
27 21 public function __construct()
@@ -55,9 +49,9 @@
55 49 }
56 50
57 51 private function getJSFileSrc($postId)
58 52 {
59 - $formUpdateVersion = get_option('bitform_form_update_version');
53 + $formUpdateVersion = get_option('bit-form_form_update_version');
60 54 $formScriptSrc = BITFORMS_UPLOAD_BASE_URL . "/form-scripts/$postId/bitform-js-$postId.js?bfv=$formUpdateVersion";
61 55
62 56 return $formScriptSrc;
63 57 }
@@ -83,12 +77,12 @@
83 77 $formIDs = [];
84 78 $previewMode = 'classic';
85 79 $postId = '';
86 80
87 - $formUpdateVersion = get_option('bitform_form_update_version');
81 + $formUpdateVersion = get_option('bit-form_form_update_version');
88 82 if ($formID) {
89 83 $formIDs[] = $formID;
90 - $FrontendFormManager = FrontendFormManager::getInstance($formID, 1);
84 + $FrontendFormManager = new FrontendFormManager($formID, 1);
91 85 $formInfo = $FrontendFormManager->getFormInfo();
92 86 $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier());
93 87 $formContent = $FrontendFormManager->getFormContentWithValue($this->getValuesFromQueryParams());
94 88 $formContent->formId = $formID;
@@ -130,9 +124,9 @@
130 124 return;
131 125 }
132 126 foreach ($bfFrontendFormIds as $index => $formId) {
133 127 $shortCodeCounter = $index + 1;
134 - $FrontendFormManager = FrontendFormManager::getInstance($formId, $shortCodeCounter);
128 + $FrontendFormManager = new FrontendFormManager($formId, $shortCodeCounter);
135 129 $formInfo = $FrontendFormManager->getFormInfo();
136 130 $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier());
137 131 $formContent = $FrontendFormManager->getFormContentWithValue($this->getValuesFromQueryParams());
138 132 $formContent->formId = $formId;
@@ -155,11 +149,8 @@
155 149 return;
156 150 }
157 151
158 152 $frontendScriptGenObj->generateJsFile($formContents, $allFields, $contentIds, $postId, $formIDs, $previewMode);
159 - if ('preview' === $previewMode) {
160 - return;
161 - }
162 153 wp_enqueue_script('bit-form-all-script-test', $this->getJSFileSrc($postId), [], $formUpdateVersion, true);
163 154 }
164 155
165 156 private function deleteUnusedFormPageIds($postId, $formIDs)
@@ -187,15 +178,15 @@
187 178 $formModel->update(['generated_script_page_ids' => wp_json_encode($generatedScriptPageIdsDecoded)], ['id' => $formId]);
188 179 }
189 180 }
190 181 if ($regenerateScriptFlag) {
191 - $formUpdateVersion = get_option('bitform_form_update_version');
182 + $formUpdateVersion = get_option('bit-form_form_update_version');
192 183 if (!$formUpdateVersion) {
193 184 $formUpdateVersion = 1;
194 185 } else {
195 186 $formUpdateVersion = (int) $formUpdateVersion + 1;
196 187 }
197 - update_option('bitform_form_update_version', $formUpdateVersion);
188 + update_option('bit-form_form_update_version', $formUpdateVersion);
198 189 }
199 190 return $regenerateScriptFlag;
200 191 }
201 192
@@ -208,9 +199,9 @@
208 199 $postId = $post->ID;
209 200 $regenerateScriptFlag = false;
210 201 $formModel = new FormModel();
211 202 foreach ($formsIds as $formId) {
212 - $formInstance = FormManager::getInstance($formId);
203 + $formInstance = new FormManager($formId);
213 204 if (!$formInstance->isExist()) {
214 205 continue;
215 206 }
216 207 $generatedPages = $formInstance->getFormData('generated_script_page_ids');
@@ -240,11 +231,10 @@
240 231
241 232 private function addInlineScript($code, $handle = '', $position = 'after')
242 233 {
243 234 $scriptHandle = !empty($handle) ? $handle : 'bf-inline-script';
244 - $formUpdateVersion = get_option('bitform_form_update_version');
245 235 if (!wp_script_is($scriptHandle)) {
246 - wp_register_script($scriptHandle, '', [], $formUpdateVersion, true);
236 + wp_register_script($scriptHandle, '', [], '', true);
247 237 wp_enqueue_script($scriptHandle);
248 238 }
249 239 wp_add_inline_script($scriptHandle, $code, $position);
250 240 }
@@ -251,11 +241,10 @@
251 241
252 242 private function addInlineStyle($code, $handle = '')
253 243 {
254 244 $styleHandle = !empty($handle) ? $handle : 'bf-inline-style';
255 - $formUpdateVersion = get_option('bitform_form_update_version');
256 245 if (!wp_style_is($styleHandle)) {
257 - wp_register_style($styleHandle, '', [], $formUpdateVersion);
246 + wp_register_style($styleHandle, '', [], '', true);
258 247 wp_enqueue_style($styleHandle);
259 248 }
260 249 wp_add_inline_style($styleHandle, $code);
261 250 }
@@ -281,37 +270,37 @@
281 270
282 271 return $fields;
283 272 }
284 273
285 - private function executeOnUserInput($formID, $shortCodeCounter, $workFlowRunType = 'create')
274 + private function executeOnUserInput($formID, $shortCodeCounter, $fields)
286 275 {
287 - $FrontendFormManager = FrontendFormManager::getInstance($formID, $shortCodeCounter);
276 + $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter);
288 277 $previousValue = $this->getValuesFromQueryParams();
289 278 $formContent = $FrontendFormManager->getFormContentWithValue($previousValue);
290 279 $customCodesExist = strpos(FrontEndScriptGenerator::getCustomCodes($formID)['JavaScript'], 'bfVars');
291 280 if ($customCodesExist || (!empty($formContent->workFlowExist) && !empty($formContent->workFlowExist->oninput))) {
292 281 $workFlowRunHelper = new WorkFlow($formID);
293 - return $workFlowRunHelper->executeOnUserInput($workFlowRunType);
282 + return $workFlowRunHelper->executeOnUserInput('create', $fields);
294 283 }
295 284 }
296 285
297 286 private function getValuesFromQueryParams()
298 287 {
299 - // Read-only: query string parsed to pre-fill form fields. Values are sanitized per field before use.
300 288 $queryParamsValue = [];
301 289 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
302 - $reqField = wp_unslash($_SERVER['QUERY_STRING']);
290 + $reqField = $_SERVER['QUERY_STRING'];
303 291 foreach (explode('&', $reqField) as $keyValue) {
304 - if (false !== strpos($keyValue, '=')) {
292 + // $pattern = '/([a-zA-Z0-9])([a-zA-Z])\=+/';
293 + $pattern = '/([^.]+)=(.*?)([^.]+)/';
294 + $matches = preg_match($pattern, $keyValue, $matchFormat);
295 + if ($matches) {
305 296 list($field, $value) = explode('=', $keyValue, 2);
306 297
307 298 if (!trim($value)) {
308 299 continue;
309 300 }
310 - $field = sanitize_text_field(urldecode($field));
311 - if (!empty($field)) {
312 - $queryParamsValue[$field][] = sanitize_text_field(urldecode($value));
313 - }
301 +
302 + $queryParamsValue[$field][] = sanitize_text_field(urldecode($value));
314 303 }
315 304 }
316 305 }
317 306
@@ -326,11 +315,10 @@
326 315 $formID = intval($atts['form_id']);
327 316 }
328 317 if (isset($atts['entry_id'])) {
329 318 $entryId = intval($atts['entry_id']);
330 - // Read-only: entry ID from query string for shortcode render. No state mutation.
331 - } elseif (isset($_GET['bf_entry_id']) && !is_array($_GET['bf_entry_id'])) {
332 - $entryId = intval(sanitize_text_field(wp_unslash($_GET['bf_entry_id'])));
319 + } elseif (isset($_GET['bf_entry_id'])) {
320 + $entryId = $_GET['bf_entry_id'];
333 321 } else {
334 322 $entryId = false;
335 323 }
336 324 if (isset($atts['id'])) {
@@ -342,22 +330,24 @@
342 330 return __('Form ID cannot be empty', 'bit-form');
343 331 }
344 332
345 333 if (!$this->isExist($formID)) {
346 - /* translators: %s: form ID */
347 334 return sprintf(__('#%s no. Form doesn\'t exists', 'bit-form'), $formID);
348 335 }
349 336
350 - // Add-ons may detect whether the current visitor is resuming an abandoned entry.
351 - $isAbandoned = (bool) apply_filters('bitform_is_abandoned_entry', false, $formID, $entryId, $atts);
337 + // check for abandoned form entry id
338 + $isAbandoned = false;
339 + if (empty($entryId) && Utilities::isPro() && class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) {
340 + $FormAbandonment = new FormAbandonment($formID);
341 + $isAbandoned = $FormAbandonment->checkAbandonedFormEntryId();
342 + }
352 343
353 344 FrontendHelpers::setBfFrontendFormIds($formID);
354 345 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
355 346 $shortCodeCounter = count($bfFrontendFormIds);
356 - $FrontendFormManager = FrontendFormManager::getInstance($formID, $shortCodeCounter);
347 + $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter);
357 348
358 349 if (!$FrontendFormManager->checkStatus()) {
359 - /* translators: %s: form ID */
360 350 return sprintf(__('#%s no. Form is not active', 'bit-form'), $formID);
361 351 }
362 352 ob_start();
363 353 $this->loadAssets($formID, $formType);
@@ -367,11 +357,10 @@
367 357 if ($font && !$formPreview) {
368 358 wp_enqueue_style('bf-google-font', $font, '1.0.0', true);
369 359 }
370 360
371 - // Read-only: password reset token from URL for display-time validation. No state written until form is submitted.
372 361 if (!empty($_GET['token']) && !empty($_GET['id'])) {
373 - $this->validPassowordResetToken(sanitize_text_field(wp_unslash($_GET['token'])), sanitize_text_field(wp_unslash($_GET['id'])), $formID);
362 + $this->validPassowordResetToken($_GET['token'], $_GET['id'], $formID);
374 363 }
375 364
376 365 $previousValue = $this->getValuesFromQueryParams();
377 366 $errorMessages = []; // delete
@@ -388,20 +377,13 @@
388 377 $buttons = !empty($formContent->buttons) ? $formContent->buttons : '';
389 378 $additional = $formContent->additional;
390 379
391 380 // $workFlowRunType = $entryId ? 'edit' : 'create';
392 - if ($entryId && (FrontendHelpers::is_current_user_can_access($formID, 'entryEditAccess'))) {
381 + if ($entryId && (get_current_user_id() || is_admin())) {
382 + // return sprintf(__('Sorry!, You cannot edit #%s no form.', 'bit-form'), $formID);
393 383 $workFlowRunType = 'edit';
394 - $adminFormHandler = new AdminFormHandler();
395 - $getEntry = $adminFormHandler->getSingleEntry($formID, $entryId);
396 - if (FrontendHelpers::is_current_user_can_access($formID, 'entryEditAccess', '', $getEntry->__user_id)) {
397 - $fields = $this->setFieldsValue($fields, $formID, $entryId);
398 - } elseif (!$isAbandoned) {
399 - $entryId = false;
400 - $workFlowRunType = 'create';
401 - }
384 + $fields = $this->setFieldsValue($fields, $formID, $entryId);
402 385 } else {
403 - $entryId = false;
404 386 $workFlowRunType = 'create';
405 387 }
406 388
407 389 // if ($entryId) {
@@ -411,14 +393,14 @@
411 393 $fields = apply_filters('bitform_filter_before_workflow_onload_fields', $fields, $formID);
412 394 $fields = $this->triggerWorkflowOnLoad($formID, $shortCodeCounter, $fields, $workFlowRunType);
413 395 $fields = apply_filters('bitform_filter_after_workflow_onload_fields', $fields, $formID);
414 396 do_action('bitform_onload_fields', $fields, $formID);
415 - $workFlowreturnedOnUserInput = $this->executeOnUserInput($formID, $shortCodeCounter, $workFlowRunType);
397 + $workFlowreturnedOnUserInput = $this->executeOnUserInput($formID, $shortCodeCounter, $fields);
416 398
417 399 // test for form before remove
418 - $noLabelFieldTypes = ['decision-box', 'gdpr', 'html', 'shortcode', 'button', 'paypal', 'razorpay', 'recaptcha', 'turnstile', 'hcaptcha', 'stripe', 'spacer'];
400 + $noLabel = ['decision-box', 'html', 'shortcode', 'button', 'paypal', 'razorpay', 'recaptcha'];
419 401 foreach ($fields as $fldKey => $field) {
420 - if (!in_array($field->typ, $noLabelFieldTypes) && isset($field->lbl)) {
402 + if (!in_array($field->typ, $noLabel) && isset($field->lbl)) {
421 403 $lblReplaceToBackslash = str_replace('$_bf_$', '\\', $field->lbl);
422 404 $fields->{$fldKey}->lbl = FieldValueHandler::replaceSmartTagWithValue($lblReplaceToBackslash);
423 405 }
424 406 }
@@ -424,9 +406,9 @@
424 406 }
425 407 $fieldsKey = $FrontendFormManager->getFieldsKey();
426 408
427 409 $captchaV3Settings = $FrontendFormManager->getCaptchaV3Settings();
428 - if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings || $FrontendFormManager->getTurnstileSettings() || $FrontendFormManager->isFieldTypeExist('hcaptcha')) {
410 + if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings || $FrontendFormManager->getTurnstileSettings()) {
429 411 $integrationHandler = new IntegrationHandler(0);
430 412 $allFormIntegrations = $integrationHandler->getAllIntegration('app');
431 413 if (!is_wp_error($allFormIntegrations)) {
432 414 foreach ($allFormIntegrations as $integration) {
@@ -434,14 +416,12 @@
434 416 $FrontendFormManager->getCaptchaSettings()
435 417 && !is_null($integration->integration_type)
436 418 && 'gReCaptcha' === $integration->integration_type
437 419 ) {
438 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
439 - if ($integrationDetails) {
440 - $integrationDetails->id = $integration->id;
441 - $reCAPTCHA = $integrationDetails;
442 - $reCAPTCHAVersion = 'v2';
443 - }
420 + $integrationDetails = json_decode($integration->integration_details);
421 + $integrationDetails->id = $integration->id;
422 + $reCAPTCHA = $integrationDetails;
423 + $reCAPTCHAVersion = 'v2';
444 424 }
445 425
446 426 if (
447 427 $FrontendFormManager->getTurnstileSettings()
@@ -447,29 +427,18 @@
447 427 $FrontendFormManager->getTurnstileSettings()
448 428 && !is_null($integration->integration_type)
449 429 && 'turnstileCaptcha' === $integration->integration_type
450 430 ) {
451 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
452 - $turnstileSiteKey = $integrationDetails->siteKey ?? '';
431 + $integrationDetails = json_decode($integration->integration_details);
432 + $turnstileSiteKey = $integrationDetails->siteKey;
453 433 }
454 434
455 - if (
456 - $FrontendFormManager->isFieldTypeExist('hcaptcha')
457 - && !is_null($integration->integration_type)
458 - && 'hcaptcha' === $integration->integration_type
459 - ) {
460 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
461 - $hCaptchaSiteKey = $integrationDetails->siteKey ?? '';
462 - }
463 -
464 435 if ($captchaV3Settings) {
465 436 if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) {
466 - $integrationDetails = Utilities::jsonObj($integration->integration_details);
467 - if ($integrationDetails) {
468 - $integrationDetails->id = $integration->id;
469 - $reCAPTCHA = $integrationDetails;
470 - $reCAPTCHAVersion = 'v3';
471 - }
437 + $integrationDetails = json_decode($integration->integration_details);
438 + $integrationDetails->id = $integration->id;
439 + $reCAPTCHA = $integrationDetails;
440 + $reCAPTCHAVersion = 'v3';
472 441 }
473 442 }
474 443 }
475 444 }
@@ -477,11 +446,9 @@
477 446
478 447 if ($captchaV3Settings && !empty($reCAPTCHA->siteKey)) {
479 448 // DANGER: no matter what, DONT CHANGE THE SCRIPT ID OF THIS SCRIPT
480 449 $scriptId = BITFORMS_PREFIX . 'recaptcha';
481 - // External Google reCAPTCHA script; version managed by URL query param. Loaded in header because
482 - // standalone form views do not render wp_footer(), making footer enqueue unreliable.
483 - wp_enqueue_script($scriptId, "https://www.google.com/recaptcha/api.js?render={$reCAPTCHA->siteKey}", [], null, false);
450 + wp_enqueue_script($scriptId, "https://www.google.com/recaptcha/api.js?render={$reCAPTCHA->siteKey}");
484 451 }
485 452
486 453 $configs = [
487 454 'bf_separator' => BITFORMS_BF_SEPARATOR,
@@ -502,20 +469,19 @@
502 469 $paymentIntegration = $integrationHandler->getAIntegration($fldData->payIntegID);
503 470 if (is_wp_error($paymentIntegration)) {
504 471 continue;
505 472 }
506 - $paymentIntegrationRow = Utilities::firstRow($paymentIntegration);
507 473 if ('paypal' === $fldData->typ) {
508 - $integrationDetails = Utilities::jsonObj($paymentIntegrationRow->integration_details ?? '');
509 - $clientID = $integrationDetails->clientID ?? '';
474 + $integrationDetails = json_decode($paymentIntegration[0]->integration_details);
475 + $clientID = $integrationDetails->clientID;
510 476 $fields->{$fldKey}->clientId = $clientID;
511 477 } elseif ('razorpay' === $fldData->typ) {
512 - $integrationDetails = Utilities::jsonObj($paymentIntegrationRow->integration_details ?? '');
513 - $clientID = $integrationDetails->apiKey ?? '';
478 + $integrationDetails = json_decode($paymentIntegration[0]->integration_details);
479 + $clientID = $integrationDetails->apiKey;
514 480 $fields->{$fldKey}->clientId = $clientID;
515 481 } elseif ('stripe' === $fldData->typ) {
516 - $integrationDetails = Utilities::jsonObj($paymentIntegrationRow->integration_details ?? '');
517 - $publishableKey = $integrationDetails->publishableKey ?? '';
482 + $integrationDetails = json_decode($paymentIntegration[0]->integration_details);
483 + $publishableKey = $integrationDetails->publishableKey;
518 484 $fields->{$fldKey}->publishableKey = $publishableKey;
519 485 }
520 486 }
521 487 }
@@ -535,14 +501,13 @@
535 501 'appID' => "bitforms_{$formID}",
536 502 'GCLID' => $FrontendFormManager->isGCLIDEnabled(),
537 503 'assetUrl' => BITFORMS_ASSET_URI,
538 504 'onfieldCondition' => !empty($workFlowreturnedOnUserInput['onfield_input_conditions']) ? $workFlowreturnedOnUserInput['onfield_input_conditions'] : false,
539 - 'smartTags' => $this->buildFrontendSmartTags($formID, $workFlowreturnedOnUserInput, $fields),
505 + 'smartTags' => SmartTags::smartTags(SmartTags::getPostUserData()),
540 506 'paymentCallbackUrl' => get_rest_url() . 'bitform/v1/payments/razorpay',
541 507 'gRecaptchaSiteKey' => !empty($reCAPTCHA->siteKey) ? $reCAPTCHA->siteKey : null,
542 508 'gRecaptchaVersion' => !empty($reCAPTCHAVersion) ? $reCAPTCHAVersion : null,
543 - 'turnstileSiteKey' => !empty($turnstileSiteKey) ? $turnstileSiteKey : null,
544 - 'hCaptchaSiteKey' => !empty($hCaptchaSiteKey) ? $hCaptchaSiteKey : null,
509 + 'turnstileSiteKey' => !empty($turnstileSiteKey) ? $turnstileSiteKey : null
545 510 ];
546 511
547 512 if ($entryId) {
548 513 $bitFormFrontArr['entryId'] = $entryId;
@@ -554,14 +519,13 @@
554 519
555 520 if (!empty($isAbandoned)) {
556 521 $bitFormFrontArr['oldValues'] = $this->getFieldsValue($formID, $isAbandoned);
557 522 if (empty($entryId)) {
558 - $bitFormFrontArr['entryId'] = $entryId;
523 + $bitFormFrontArr['entryId'] = $isAbandoned;
559 524 }
560 525 }
561 526
562 527 $formInfo = $FrontendFormManager->getFormInfo();
563 - $bitFormFrontArr['formName'] = $formInfo->formName ?? '';
564 528 if (is_array($layout) && count($layout) > 1) {
565 529 $multiStepSettings = isset($formInfo->multiStepSettings) ? $formInfo->multiStepSettings : null;
566 530 $newTempSettings = (object) [
567 531 'validateOnStepChange' => isset($multiStepSettings->validateOnStepChange) ? $multiStepSettings->validateOnStepChange : false,
@@ -587,24 +551,27 @@
587 551 'formAbandonment' => $formAbandonmentSettings
588 552 ];
589 553 }
590 554
555 + $bitFormsFront = apply_filters(
556 + 'bitforms_localized_script',
557 + $bitFormFrontArr
558 + );
559 +
591 560 $layout = wp_json_encode($layout);
592 561 $buttons = wp_json_encode($buttons);
593 562 $frontArr = wp_json_encode($bitFormFrontArr);
594 563
595 - $bfGlobals = sprintf('
564 + $bfGlobals = <<<BFGLOBALS
596 565 if(!window.bf_globals) {
597 566 window.bf_globals = {}
598 - } if(!window.bf_globals.%1$s) {
599 - window.bf_globals.%1$s = {}
567 + } if(!window.bf_globals.{$FormIdentifier}) {
568 + window.bf_globals.{$FormIdentifier} = {}
600 569 }
601 - if(document.getElementById("%1$s")) {
602 - window.bf_globals.%1$s = {
603 - ...window.bf_globals.%1$s,
604 - ...%2$s
605 - };
606 - }', $FormIdentifier, $frontArr);
570 + if(document.getElementById('{$FormIdentifier}')) {
571 + window.bf_globals.{$FormIdentifier} = {...window.bf_globals.{$FormIdentifier}, ...{$frontArr}};
572 + }
573 +BFGLOBALS;
607 574
608 575 if ('conversational' === $formType
609 576 && isset($formContent->formInfo->conversationalSettings->enable)
610 577 && $formContent->formInfo->conversationalSettings->enable) {
@@ -619,87 +586,17 @@
619 586 $formViewObject = new \stdClass();
620 587 $formViewObject->html = $html;
621 588 $formViewObject->font = $font;
622 589 $formViewObject->bfGlobals = $bfGlobals;
623 - $formViewObject->formContent = $formContent;
624 590 return $formViewObject;
625 591 }
626 -
627 - $bfGlobalsHandle = 'bitform-bf-globals-' . sanitize_key($FormIdentifier);
628 - $this->addInlineScript($bfGlobals, $bfGlobalsHandle, 'after');
629 - $this->emitShowPickerBridge();
630 -
631 - echo wp_kses(trim($html), EscapingHelper::getFormAllowedHtml($formContent));
592 + $html .= <<<BFGLOBALSSCRIPT
593 + <script id="bit-form-bf-globals-{$FormIdentifier}">{$bfGlobals}</script>
594 +BFGLOBALSSCRIPT;
595 + echo trim($html);
632 596 return ob_get_clean();
633 597 }
634 598
635 - /**
636 - * Build the smart-tag map exposed to the browser in window.bf_globals[formId].smartTags.
637 - *
638 - * Security: the legacy code shipped the ENTIRE ~43-tag map to every visitor, leaking
639 - * PII (admin/user/author email) and freezing per-visitor request data (IP, time,
640 - * browser, referer) into cacheable HTML. We now emit ONLY tags that are (a) actually
641 - * referenced by this form's client-evaluated surfaces — conditional logic, payment
642 - * notes, admin custom JS — AND (b) flagged frontend-safe in the registry (static/post
643 - * context only). Sensitive (identity) and request/visitor tags are never emitted; they
644 - * resolve server-side at submit time instead.
645 - *
646 - * @param int|string $formID
647 - * @param mixed $workflowConditions on-field input conditions (client-evaluated)
648 - * @param mixed $fields form fields object (carries payment notes, etc.)
649 - * @return array<string,string>
650 - */
651 - private function buildFrontendSmartTags($formID, $workflowConditions, $fields)
652 - {
653 - // Haystack = only surfaces the browser actually evaluates against smartTags.
654 - $haystack = wp_json_encode($workflowConditions) . ' ' . wp_json_encode($fields);
655 - $customJs = FrontEndScriptGenerator::getCustomCodes($formID)['JavaScript'];
656 - if (is_string($customJs) && '' !== $customJs) {
657 - $haystack .= ' ' . $customJs;
658 - }
659 -
660 - $ctx = SmartTags::getPostUserData();
661 - $frontendSmartTags = [];
662 - $referenced = [];
663 - foreach (SmartTags::smartTagFieldKeys() as $key) {
664 - if (!SmartTagRegistry::isFrontendExposable($key)) {
665 - continue; // identity / request / param tags never travel to the browser
666 - }
667 - // Match '${' . key prefix so keys containing spaces/slashes/commas are handled.
668 - if (false !== strpos($haystack, '${' . $key)) {
669 - $referenced[] = $key;
670 - $frontendSmartTags[$key] = SmartTagRegistry::resolve($key, $ctx);
671 - }
672 - }
673 -
674 - /**
675 - * Escape hatch: a site that genuinely needs an extra tag client-side can opt it
676 - * back in explicitly here, rather than core shipping everything by default.
677 - *
678 - * @param array<string,string> $frontendSmartTags resolved frontend-safe smart tags
679 - * @param int|string $formID
680 - * @param string[] $referenced keys detected in client surfaces
681 - */
682 - return apply_filters('bitform_frontend_smarttags', $frontendSmartTags, $formID, $referenced);
683 - }
684 -
685 - /**
686 - * Delegated listener that opens the native picker on date/time inputs marked
687 - * with data-bf-show-picker. Replaces the legacy hardcoded onclick attribute.
688 - * Registered as inline script once per request via wp_add_inline_script so
689 - * the markup never travels through wp_kses().
690 - */
691 - private function emitShowPickerBridge()
692 - {
693 - static $emitted = false;
694 - if ($emitted) {
695 - return;
696 - }
697 - $emitted = true;
698 - $code = 'if(!window.__bfShowPickerBound){window.__bfShowPickerBound=true;document.addEventListener("click",function(e){var t=e.target;if(t&&t.matches&&t.matches("input[data-bf-show-picker=\"1\"]")&&typeof t.showPicker==="function"){try{t.showPicker();}catch(_){}}});}';
699 - $this->addInlineScript($code, 'bitform-show-picker-bridge', 'after');
700 - }
701 -
702 599 private function isExist($formID)
703 600 {
704 601 $formModel = new FormModel();
705 602 $form = $formModel->get(
@@ -717,9 +614,8 @@
717 614 }
718 615
719 616 private function getFieldsValue($formID, $entryID)
720 617 {
721 - $FrontendFormManager = FrontendFormManager::getInstance($formID, 1);
722 618 $formEntryModel = new FormEntryMetaModel();
723 619 $metaValues = $formEntryModel->get(
724 620 [
725 621 'meta_key',
@@ -728,9 +624,8 @@
728 624 [
729 625 'bitforms_form_entry_id' => $entryID,
730 626 ]
731 627 );
732 - $formFields = $FrontendFormManager->getFields();
733 628 $fldsData = (object) [];
734 629 if (!is_wp_error($metaValues)) {
735 630 foreach ($metaValues as $metaValue) {
736 631 $metaKey = $metaValue->meta_key;
@@ -748,11 +643,8 @@
748 643 if (!isset($fldsData->{$metaKey})) {
749 644 $fldsData->{$metaKey} = '';
750 645 }
751 646 $fldsData->{$metaKey} = $metaVal;
752 - if (isset($formFields[$metaKey]['type']) && in_array($formFields[$metaKey]['type'], ['file-up', 'advanced-file-up'])) {
753 - $fldsData->{$metaKey} = $metaValue->meta_value;
754 - }
755 647 }
756 648 }
757 649
758 650 return $fldsData;
@@ -770,23 +662,8 @@
770 662 'bitforms_form_entry_id' => $entryID,
771 663 ]
772 664 );
773 665 if (!is_wp_error($metaValues)) {
774 - $urlQuery = wp_parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
775 - $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
776 - $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
777 - $baseDLURL .= "formID={$formID}&entryID={$entryID}";
778 -
779 - foreach ($fields as $field) {
780 - if ('file-up' === $field->typ || 'advanced-file-up' === $field->typ) {
781 - if (!isset($field->config)) {
782 - $field->config = (object) [];
783 - } elseif (is_array($field->config)) {
784 - $field->config = (object) $field->config;
785 - }
786 - $field->config->baseDLURL = $baseDLURL;
787 - }
788 - }
789 666 foreach ($metaValues as $metaValue) {
790 667 $metaKey = $metaValue->meta_key;
791 668 $metaVal = $metaValue->meta_value;
792 669 // if meta value is array then convert to string
@@ -803,8 +680,12 @@
803 680 $fields->{$metaKey}->val = $metaVal;
804 681 if ('file-up' === $fields->{$metaKey}->typ || 'advanced-file-up' === $fields->{$metaKey}->typ) {
805 682 $fields->{$metaKey}->val = $metaValue->meta_value;
806 683 $fields->{$metaKey}->config->oldFiles = $metaValue->meta_value;
684 + $urlQuery = wp_parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
685 + $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
686 + $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
687 + $fields->{$metaKey}->config->baseDLURL = $baseDLURL . "formID={$formID}&entryID={$entryID}";
807 688 }
808 689 }
809 690 }
810 691 }
@@ -831,9 +712,9 @@
831 712 $newFormId = $formID . '-formid';
832 713 } else {
833 714 $newFormId = $formID;
834 715 }
835 - $formUpdateVersion = get_option('bitform_form_update_version');
716 + $formUpdateVersion = get_option('bit-form_form_update_version');
836 717 if (!wp_style_is('bitform-style-' . $newFormId) && is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css')) {
837 718 wp_enqueue_style(
838 719 'bitform-style-' . $newFormId,
839 720 BITFORMS_UPLOAD_BASE_URL . "/form-styles/bitform-{$newFormId}.css",
@@ -841,9 +722,9 @@
841 722 $formUpdateVersion
842 723 );
843 724 if ($isPageBuilder) {
844 725 $formStyle = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css');
845 - echo '<style id="bitform-style-' . esc_attr((string) $newFormId) . '">' . wp_kses($formStyle, []) . '</style>';
726 + echo sprintf("<style id='bitform-style-{$newFormId}'>%s</style>", $formStyle);
846 727 }
847 728 }
848 729 if (!wp_style_is('bitform-style-custom-' . $formID) && is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $formID . '.css')) {
849 730 wp_enqueue_style(
@@ -853,9 +734,9 @@
853 734 $formUpdateVersion
854 735 );
855 736 if ($isPageBuilder) {
856 737 $formStyle = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $formID . '.css');
857 - echo '<style id="bitform-style-custom-' . esc_attr((string) $formID) . '">' . wp_kses($formStyle, []) . '</style>';
738 + echo sprintf("<style id='bitform-style-custom-{$formID}'>%s</style>", $formStyle);
858 739 }
859 740 }
860 741 // load conversational form css
861 742 if ('conversational' === $fromType) {