PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.7.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.7.0
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
← All changes | includes/Admin/Form/FrontEndScriptGenerator.php +182 -168 3.2.22.7.0 View file →
@@ -1,14 +1,18 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Admin\Form;
4 4
5 -if (!defined('ABSPATH')) {
6 - exit;
7 -}
8 -
9 -use BitCode\BitForm\Core\Util\FileHandler;
5 +use BitCode\BitForm\Admin\Form\InitJs\Paypal;
6 +use BitCode\BitForm\Admin\Form\InitJs\Razorpay;
7 +use BitCode\BitForm\Admin\Form\InitJs\Recaptcha;
8 +use BitCode\BitForm\Admin\Form\InitJs\RecaptchaV3;
9 +use BitCode\BitForm\Admin\Form\InitJs\ScriptLoader;
10 +use BitCode\BitForm\Admin\Form\InitJs\Stripe;
10 11 use BitCode\BitForm\Core\Util\Log;
12 +use BitCode\BitForm\Core\Util\Utilities;
13 +use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler;
14 +use BitCode\BitFormPro\Admin\FormSettings\FormAbandonment;
11 15 use WP_Error;
12 16
13 17 class FrontEndScriptGenerator
14 18 {
@@ -24,16 +28,17 @@
24 28 $this->_scriptAddedFlags = [];
25 29 $this->_fields = [];
26 30 $this->_jsFilesNeeded = [];
27 31 $this->_loadedScriptsList = [];
28 - $this->_validationJsFilesNeeded = ScriptFilePriorityManager::validationAndOtherScriptFile();
32 + $this->_validationJsFilesNeeded = ScriptFilePriorityManager::validationScriptFile();
29 33 }
30 34
31 35 private static function generateBfGlobalObjJS($contentIds = [])
32 36 {
33 - $contentidArray = wp_json_encode($contentIds);
34 - return ' if(!window.bf_globals){ window.bf_globals = {};}
35 - ' . $contentidArray . '.forEach(function(contentId){
37 + $contentidArray = json_encode($contentIds);
38 + return <<<GLOBALOBJ
39 + if(!window.bf_globals){ window.bf_globals = {};}
40 + $contentidArray.forEach(function(contentId){
36 41 const form = document.getElementById(contentId);
37 42 if(!form){
38 43 delete window.bf_globals[contentId];
39 44 return;
@@ -44,14 +49,15 @@
44 49 window.bf_globals[contentId].inits = {};
45 50 window.bf_globals[contentId].contentId = contentId;
46 51 }
47 52
48 - });';
53 + });
54 +GLOBALOBJ;
49 55 }
50 56
51 57 private static function isValidationNeeded($fldData)
52 58 {
53 - $validationsToCheck = ['valid->req', 'valid->regexr', 'mn', 'mx', 'opt', 'err->invalid->show', 'err->notVerified->show'];
59 + $validationsToCheck = ['valid->req', 'valid->regexr', 'mn', 'mx', 'opt', 'err->invalid->show'];
54 60 foreach ($validationsToCheck as $property) {
55 61 $needValidation = Helpers::property_exists_nested($fldData, $property);
56 62 if ($needValidation) {
57 63 return true;
@@ -59,9 +65,9 @@
59 65 }
60 66 return false;
61 67 }
62 68
63 - public function generateJsFile($formContents, $fields, $contentIds, $postId, $formIDs = null, $preview = 'classic')
69 + public function generateJsFile($formContents, $fields, $contentIds, $postId, $formIDs = null, $preview = false)
64 70 {
65 71 add_option('bitforms_frontend_js_generating', true);
66 72 $this->_formContents = $formContents;
67 73 $this->_fields = $fields;
@@ -85,11 +91,8 @@
85 91
86 92 // for hidden Field when cache plugin on
87 93 $this->jsHiddenFieldScript();
88 94
89 - // for recaptcha v3 (form-level setting)
90 - $this->jsRecaptchaV3Scripts();
91 -
92 95 // for form abandonment scripts
93 96 $this->jsFormAbandonmentScripts();
94 97
95 98 // multi step form scripts
@@ -94,11 +97,8 @@
94 97
95 98 // multi step form scripts
96 99 $this->multiStepFormScripts();
97 100
98 - // conversational form scripts
99 - $this->conversationalFormScripts();
100 -
101 101 //⚠👆 every script file generate method call before this method
102 102 $this->appendJs($this->getScript(), $postId, $preview);
103 103 $this->appendJs($this->generateFieldConfigsJs($contentIds), $postId, $preview);
104 104 // init all js events and functions at last
@@ -125,49 +125,64 @@
125 125 }
126 126 }
127 127 }
128 128
129 - private function conversationalFormScripts()
129 + private function jsFormAbandonmentScripts()
130 130 {
131 + if (!Utilities::isPro() || !class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) {
132 + return;
133 + }
134 + // check if any of the form has form abandonment enabled
135 + $allFiles = [];
131 136 foreach ($this->_formContents as $formContent) {
132 - if (!empty($formContent->formInfo->conversationalSettings) && $formContent->formInfo->conversationalSettings->enable) {
133 - $files = ScriptFilePriorityManager::conversationalFormFiles();
134 - foreach ($files as $file) {
135 - $this->addScriptInLoadedScriptsList($file);
137 + $formAbandonmentSettings = FormAbandonment::getFormAbandonmentSettings($formContent->formId);
138 + if (!empty($formAbandonmentSettings->saveFormDraft)) {
139 + $neededFiles = ScriptFilePriorityManager::formAbandonmentNeededFiles('autoSave');
140 + $allFiles = array_merge($allFiles, $neededFiles);
141 + break;
142 + }
143 +
144 + $workflowHandler = new WorkFlowHandler($formContent->formId);
145 + $allWorkflows = $workflowHandler->getAllworkFlow();
146 + foreach ($allWorkflows as $workflow) {
147 + foreach ($workflow['conditions'] as $cond) {
148 + if (!empty($cond->actions) && !empty($cond->actions->fields)) {
149 + foreach ($cond->actions->fields as $fldAction) {
150 + if (empty($fldAction->field) || empty($fldAction->action)) {
151 + continue;
152 + }
153 + if ('_bf_form' === $fldAction->field && 'save_draft' === $fldAction->action) {
154 + $neededFiles = ScriptFilePriorityManager::formAbandonmentNeededFiles();
155 + $allFiles = array_merge($allFiles, $neededFiles);
156 + }
157 + }
158 + }
136 159 }
137 160 }
138 161 }
139 - }
140 -
141 - private function jsFormAbandonmentScripts()
142 - {
143 - /**
144 - * Add-ons can inject required script files here.
145 - *
146 - * @param array $files Array of file arrays: ['priority' => int, 'filename' => string]
147 - * @param array $formContents
148 - * @param array $fields
149 - */
150 - $files = apply_filters('bitform_form_abandonment_script_files', [], $this->_formContents, $this->_fields);
151 - if (empty($files) || !is_array($files)) {
162 + if (isset($this->_fields['button'])) {
163 + foreach ($this->_fields['button'] as $button) {
164 + if ('save-draft' === $button['field']->btnTyp) {
165 + $neededFiles = ScriptFilePriorityManager::formAbandonmentNeededFiles('draftButton');
166 + $allFiles = array_merge($allFiles, $neededFiles);
167 + break;
168 + }
169 + }
170 + }
171 + //
172 + if (empty($allFiles)) {
152 173 return;
153 174 }
154 - foreach ($files as $jsFile) {
155 - if (!empty($jsFile['filename']) && !empty($jsFile['priority'])) {
156 - $this->addScriptInLoadedScriptsList($jsFile);
157 - }
175 + foreach ($allFiles as $jsFile) {
176 + $this->addScriptInLoadedScriptsList($jsFile);
158 177 }
159 178 }
160 179
161 - private function appendJs($script, $postId, $previewMode, $mode = 'a')
180 + private function appendJs($script, $postId, $preview, $mode = 'a')
162 181 {
163 182 $fileName = '';
164 183 $path = '';
165 -
166 - if ('conversational' === $previewMode) {
167 - $fileName = "bitform-conversational-{$postId}.js";
168 - $path = 'form-scripts';
169 - } elseif ('preview' === $previewMode) {
184 + if ($preview) {
170 185 $fileName = "preview-{$postId}.js";
171 186 $path = 'form-scripts';
172 187 } else {
173 188 $fileName = "bitform-js-$postId.js";
@@ -184,12 +199,22 @@
184 199
185 200 $script = '';
186 201 foreach ($this->_loadedScriptsList as $scriptFileArr) {
187 202 $fileNam = $scriptFileArr['filename'];
188 - $fileContent = self::getFileFromAssetsJs($fileNam);
189 - if ($fileContent) {
190 - $script .= $fileContent;
203 + if (!isset($scriptFileArr['scriptTyp']) || 'script' === $scriptFileArr['scriptTyp']) {
204 + if (self::getFileFromAssetsJs($fileNam)) {
205 + $script .= self::getFileFromAssetsJs($fileNam);
206 + continue;
207 + }
208 + continue;
191 209 }
210 + if ('custom' === $scriptFileArr['scriptTyp']) {
211 + $fileInstance = $scriptFileArr['source'] . $fileNam;
212 + if (!class_exists($fileInstance)) {
213 + continue;
214 + } // when class not found, skip load script
215 + $script .= $fileInstance::init($scriptFileArr['fk'], $scriptFileArr['field'], $scriptFileArr['contentId']);
216 + }
192 217 }
193 218 return $script;
194 219 }
195 220
@@ -197,12 +222,8 @@
197 222 {
198 223 foreach ($this->_fields as $flds) {
199 224 foreach ($flds as $fld) {
200 225 $fldData = $fld['field'];
201 - // Corrupt/partial form JSON can produce a null field or one without typ.
202 - if (!is_object($fldData)) {
203 - continue;
204 - }
205 226 // for validation js files
206 227 if (self::isValidationNeeded($fldData)) {
207 228 $validation = $this->_validationJsFilesNeeded['validation'];
208 229 $this->addScriptInLoadedScriptsList($validation);
@@ -222,30 +243,18 @@
222 243
223 244 $validationScriptFileMapping = ScriptFilePriorityManager::validationScriptFileMapping($fldData->typ);
224 245 if ($validationScriptFileMapping) {
225 246 foreach ($validationScriptFileMapping as $key => $value) {
226 - $paths = $value['paths'] ?? [];
227 - $hasMatchingPath = false;
228 - foreach ($paths as $path) {
247 + foreach ($value['paths'] as $path) {
229 248 if (Helpers::property_exists_nested($fldData, $path)) {
230 - $hasMatchingPath = true;
231 - break; // one match is enough
249 + $file = $this->_validationJsFilesNeeded[$key];
250 + $this->addScriptInLoadedScriptsList($file);
232 251 }
233 252 }
234 -
235 - if (!$hasMatchingPath) {
236 - continue;
237 - }
238 -
239 - // Add the main script once
240 - if (!empty($this->_validationJsFilesNeeded[$key])) {
241 - $this->addScriptInLoadedScriptsList($this->_validationJsFilesNeeded[$key]);
242 - }
243 -
244 - // Add dependencies once each
245 - foreach (($value['dependencies'] ?? []) as $dep) {
246 - if (!empty($this->_validationJsFilesNeeded[$dep])) {
247 - $this->addScriptInLoadedScriptsList($this->_validationJsFilesNeeded[$dep]);
253 + if (isset($value['dependencies'])) {
254 + foreach ($value['dependencies'] as $dependency) {
255 + $dependencyFile = $this->_validationJsFilesNeeded[$dependency];
256 + $this->addScriptInLoadedScriptsList($dependencyFile);
248 257 }
249 258 }
250 259 }
251 260 }
@@ -254,9 +263,8 @@
254 263 }
255 264
256 265 private function jsFieldsNeededFile()
257 266 {
258 - $filePondPluginList = apply_filters('bitform_filepond_plugins_list', []);
259 267 foreach ($this->_fields as $typ => $flds) {
260 268 if (!array_key_exists($typ, $this->_jsFilesNeeded)) {
261 269 continue;
262 270 }
@@ -266,30 +274,26 @@
266 274 if ('advanced-file-up' === $typ) {
267 275 $configs = $fld['field']->config;
268 276 foreach ($configs as $configKey => $config) {
269 277 if ($configs->$configKey) {
270 - if (array_key_exists($configKey, $filePondPluginList)) {
271 - $this->addScriptInLoadedScriptsList($filePondPluginList[$configKey]);
278 + $filepondPlugin = ScriptFilePriorityManager::filePondPlugins($configKey);
279 + if ($filepondPlugin) {
280 + $this->addScriptInLoadedScriptsList($filepondPlugin);
272 281 }
273 282 }
274 283 }
275 284 }
276 285 foreach ($fldScriptArr as $scriptFile) {
277 - if (isset($scriptFile['paths']) && is_array($scriptFile['paths'])) {
278 - $pathMatched = false;
279 - foreach ($scriptFile['paths'] as $path) {
280 - if (Helpers::property_exists_nested($fld['field'], $path)) {
281 - $pathMatched = true;
282 - break;
283 - }
284 - }
285 - if (!$pathMatched) {
286 - continue;
287 - }
288 - } elseif (isset($scriptFile['path']) && !Helpers::property_exists_nested($fld['field'], $scriptFile['path'])) {
286 + if (!isset($scriptFile['scriptTyp'])) {
287 + $this->addScriptInLoadedScriptsList($scriptFile);
289 288 continue;
290 289 }
291 - $this->addScriptInLoadedScriptsList($scriptFile);
290 + if ('custom' === $scriptFile['scriptTyp'] && Helpers::property_exists_nested($fld['field'], $scriptFile['path'], true)) {
291 + $scriptFile['field'] = $fld['field'];
292 + $scriptFile['fk'] = $fld['fk'];
293 + $scriptFile['contentId'] = $fld['contentId'];
294 + $this->addScriptInLoadedScriptsList($scriptFile);
295 + }
292 296 }
293 297 }
294 298 }
295 299 }
@@ -295,15 +299,13 @@
295 299 }
296 300
297 301 private static function getCustomJsCodes($contentIds = [])
298 302 {
299 - $script = 'let bfContentId = "", bfSlNo = "1", bfVars= "";';
303 + $script = 'let bfContentId = "", bfVars= "";';
300 304 foreach ($contentIds as $contentId) {
301 - $contentIdArr = explode('_', $contentId);
302 - $jsCode = self::getCustomCodes($contentIdArr[1])['JavaScript'];
303 - $bfSlNo = array_key_exists(3, $contentIdArr) ? $contentIdArr[3] : '1';
305 + $jsCode = self::getCustomCodes(explode('_', $contentId)[1])['JavaScript'];
304 306 if (!empty($jsCode)) {
305 - $script .= " if(bfSelect('#{$contentId}')){ bfContentId = '{$contentId}'; bfSlNo = '{$bfSlNo}'; bfVars = window.bf_globals.{$contentId}.smartTags; {$jsCode}}";
307 + $script .= " if(bfSelect('#{$contentId}')){ bfContentId = '{$contentId}'; bfVars = window.bf_globals.{$contentId}.smartTags; {$jsCode}}";
306 308 }
307 309 }
308 310
309 311 return $script;
@@ -333,10 +335,9 @@
333 335 {
334 336 // for js file
335 337 $path = 'form-scripts';
336 338 $fileName = "bitform-custom-$formId.js";
337 - $filteredJs = Helpers::removeJsSingleLineComments($customCodes->JavaScript);
338 - self::customCodeFileSaveOrDelete($filteredJs, $path, $fileName);
339 + self::customCodeFileSaveOrDelete($customCodes->JavaScript, $path, $fileName);
339 340
340 341 // for css file
341 342 $path = 'form-styles';
342 343 $fileName = "bitform-custom-$formId.css";
@@ -351,9 +352,11 @@
351 352 Helpers::saveFile($path, $fileName, $script, 'w');
352 353 } else {
353 354 $uploadPath = "$path/$fileName";
354 355 $uploadFilePath = Helpers::generatePathDirOrFile($uploadPath);
355 - FileHandler::deleteIsFileExists($uploadFilePath);
356 + if (file_exists($uploadFilePath)) {
357 + unlink($uploadFilePath);
358 + }
356 359 }
357 360 return true;
358 361 }
359 362
@@ -369,31 +372,26 @@
369 372 return $customCodes;
370 373 }
371 374
372 375 private $fldContainersByType = [
373 - 'address' => '.__$fk__-parent-fld-wrp',
374 - 'select' => '.__$fk__-dpd-fld-wrp',
375 - 'country' => '.__$fk__-country-fld-wrp',
376 - 'currency' => '.__$fk__-currency-fld-wrp',
377 - 'phone-number' => '.__$fk__-phone-fld-wrp',
378 - 'file-up' => '.__$fk__-file-up-wrpr',
379 - 'advanced-file-up' => '#filepond-__$fk__-container',
380 - 'paypal' => '.__$fk__-paypal-wrp',
381 - 'razorpay' => '.__$fk__-razorpay-wrp',
382 - 'recaptcha' => '.__$fk__-recaptcha-wrp',
383 - 'stripe' => '.__$fk__-stripe-fld',
384 - 'mollie' => '.__$fk__-mollie-wrp',
385 - 'repeater' => '.__$fk__-rpt-fld-wrp',
386 - 'signature' => '.__$fk__-inp-fld-wrp',
387 - 'rating' => '.__$fk__-inp-fld-wrp',
388 - 'email-otp' => '.__$fk__-inp-fld-wrp',
389 - 'hcaptcha' => '.__$fk__-h-captcha-wrp',
390 - 'advanced-datetime' => '.__$fk__-advanced-datetime',
376 + 'select' => '.__$fk__-dpd-fld-wrp',
377 + 'country' => '.__$fk__-country-fld-wrp',
378 + 'currency' => '.__$fk__-currency-fld-wrp',
379 + 'phone-number' => '.__$fk__-phone-fld-wrp',
380 + 'file-up' => '.__$fk__-file-up-wrpr',
381 + 'advanced-file-up' => '#filepond-__$fk__-container',
382 + 'paypal' => '.__$fk__-paypal-wrp',
383 + 'razorpay' => '.__$fk__-razorpay-wrp',
384 + 'recaptcha' => '.__$fk__-recaptcha-wrp',
385 + 'stripe' => '.__$fk__-stripe-fld',
386 + 'repeater' => '.__$fk__-rpt-fld-wrp',
387 + 'signature' => '.__$fk__-inp-fld-wrp',
388 + 'rating' => '.__$fk__-inp-fld-wrp',
391 389 ];
392 390
393 391 private function generateFieldConfigsJs()
394 392 {
395 - $customFlds = ['address', 'select', 'country', 'currency', 'phone-number', 'file-up', 'advanced-file-up', 'paypal', 'razorpay', 'stripe', 'mollie', 'recaptcha', 'repeater', 'signature', 'rating', 'turnstile', 'hcaptcha', 'advanced-datetime', 'email-otp'];
393 + $customFlds = ['select', 'country', 'currency', 'phone-number', 'file-up', 'advanced-file-up', 'paypal', 'razorpay', 'stripe', 'recaptcha', 'repeater', 'signature', 'rating'];
396 394 $allFieldTypes = array_keys($this->_fields);
397 395 $customFldsInForms = array_intersect($allFieldTypes, $customFlds);
398 396 $formContents = $this->_formContents;
399 397 $recaptchaV3Enabled = false;
@@ -415,10 +413,10 @@
415 413 }
416 414
417 415 $customFldConfigPaths = [];
418 416
419 - $allConfs = ScriptFilePriorityManager::getAllFldConfs();
420 417 foreach ($customFldsInForms as $customFldTyp) {
418 + $allConfs = ScriptFilePriorityManager::getAllFldConfs();
421 419 if (isset($allConfs[$customFldTyp])) {
422 420 $customFldConfigPaths[$customFldTyp] = $allConfs[$customFldTyp];
423 421 } else {
424 422 $customFldConfigPaths[$customFldTyp] = (object) [];
@@ -424,48 +422,84 @@
424 422 $customFldConfigPaths[$customFldTyp] = (object) [];
425 423 }
426 424 }
427 425
428 - $customFldConfigPaths = wp_json_encode($customFldConfigPaths);
429 - $containers = wp_json_encode($containers);
426 + $customFldConfigPaths = json_encode($customFldConfigPaths);
427 + $containers = json_encode($containers);
430 428
431 - $script = ' const customFldConfigPaths = ' . $customFldConfigPaths . ';
432 - const fldContainers = ' . $containers . ';
429 + $scriptLoaderFields = ['paypal', 'razorpay', 'stripe', 'recaptcha'];
430 + $scriptLoadedNeeded = array_intersect($scriptLoaderFields, $customFldsInForms) || $recaptchaV3Enabled;
431 + if ($scriptLoadedNeeded) {
432 + $scriptLoaderJs = ScriptLoader::init();
433 + } else {
434 + $scriptLoaderJs = '';
435 + }
436 +
437 + if (in_array('paypal', $customFldsInForms)) {
438 + $paypalInitJs = Paypal::init();
439 + } else {
440 + $paypalInitJs = '';
441 + }
442 +
443 + if (in_array('razorpay', $customFldsInForms)) {
444 + $razorpayInitJs = Razorpay::init();
445 + } else {
446 + $razorpayInitJs = '';
447 + }
448 +
449 + if (in_array('stripe', $customFldsInForms)) {
450 + $stripeInitJs = Stripe::init();
451 + } else {
452 + $stripeInitJs = '';
453 + }
454 +
455 + if (in_array('recaptcha', $customFldsInForms)) {
456 + $recaptchaInitJs = Recaptcha::init();
457 + } else {
458 + $recaptchaInitJs = '';
459 + }
460 +
461 + if ($recaptchaV3Enabled) {
462 + $recaptchaV3InitJs = RecaptchaV3::init();
463 + } else {
464 + $recaptchaV3InitJs = '';
465 + }
466 +
467 + $script = <<<FIELDCONFIGJS
468 + const customFldConfigPaths = $customFldConfigPaths;
469 + const fldContainers = $containers;
433 470
471 + $scriptLoaderJs;
472 +
434 473 function initAllCustomFlds (formContentId = null) {
435 474 const allContendIds = formContentId ? [formContentId] : Object.keys(bf_globals);
436 475 allContendIds.forEach((contentId) => {
437 476 const contentData = bf_globals[contentId];
438 - if(!contentData?.inits) contentData.inits = {};
439 - const flds = bf_globals[contentId]?.fields || {};
477 + const flds = bf_globals[contentId].fields;
440 478 const fldKeys = Object.keys(flds).reverse();
441 479 fldKeys.forEach((fldKey) => {
442 480 const fldData = flds[fldKey];
443 481 const fldType = fldData.typ;
444 - if(fldType === \'paypal\') {
445 - initPaypalFld(contentId, fldKey, fldData, fldType);
446 - } else if(fldType === \'razorpay\') {
447 - initRazorpayFld(contentId, fldKey, fldType);
448 - } else if(fldType === \'recaptcha\') {
449 - initRecaptchaFld(contentId, fldKey, fldType);
450 - } else if(fldType === \'turnstile\') {
451 - initTurnstileFld(contentId, fldKey);
452 - } else if(fldType === \'hcaptcha\') {
453 - initHCaptchaFld(contentId, fldKey, fldType);
454 - } else if(fldType === \'stripe\' || fldType === \'mollie\') {
455 - initStripeFld(contentId, fldKey, fldType);
482 + if(fldType === 'paypal') {
483 + $paypalInitJs;
484 + } else if(fldType === 'razorpay') {
485 + $razorpayInitJs;
486 + } else if(fldType === 'recaptcha') {
487 + $recaptchaInitJs;
488 + } else if(fldType === 'stripe') {
489 + $stripeInitJs;
456 490 } else if (customFldConfigPaths[fldType]) {
457 491 contentData.inits[fldKey] = getFldInstance(contentId, fldKey, fldType);
458 492 }
459 493 });
460 - if(contentData.gRecaptchaVersion === \'v3\' && contentData.gRecaptchaSiteKey){
461 - initRecaptchaV3Fld(contentId, contentData);
494 + if(contentData.gRecaptchaVersion === 'v3' && contentData.gRecaptchaSiteKey){
495 + $recaptchaV3InitJs;
462 496 }
463 497 });
464 498 };
465 - function getFldInstance(contentId, fldKey, fldTyp, nestedSelector = \'\') {
466 - const fldClass = this[\'bit_\'+fldTyp.replace(/-/g, \'_\')+\'_field\'];
467 - const selector = \'#form-\'+contentId+\' \'+nestedSelector+fldContainers[fldTyp].replace("__$fk__", fldKey);
499 + function getFldInstance(contentId, fldKey, fldTyp, nestedSelector = '') {
500 + const fldClass = this['bit_'+fldTyp.replace(/-/g, '_')+'_field'];
501 + const selector = '#form-'+contentId+' '+nestedSelector+fldContainers[fldTyp].replace("__\$fk__", fldKey);
468 502 if(!fldClass || !bfSelect(selector)) return;
469 503 return new fldClass(selector, getFldConf(contentId, fldKey, fldTyp));
470 504 };
471 505 function getFldConf(contentId, fieldKey, fldTyp) {
@@ -486,13 +520,13 @@
486 520 } else {
487 521 value = getDataFromNestedPath(fldData, fldPath.path);
488 522 }
489 523 }
490 - if (!value && "val" in fldPath) {
524 + if (!value && fldPath.val) {
491 525 value = fldPath.val;
492 - if(typeof value === \'string\') {
526 + if(typeof value === 'string') {
493 527 Object.entries(varData).forEach(([key, val]) => {
494 - value = value.replace("__$"+key+"__", val);
528 + value = value.replace("__\$"+key+"__", val);
495 529 });
496 530 }
497 531 }
498 532 fldConf = setDataToNestedPath(fldConf, confPath, value);
@@ -518,9 +552,10 @@
518 552 current = current[k];
519 553 });
520 554 current[lastKey] = value;
521 555 return current;
522 - }';
556 + }
557 +FIELDCONFIGJS;
523 558
524 559 return $script;
525 560 }
526 561
@@ -537,21 +572,17 @@
537 572 private function jsFrontendScript()
538 573 {
539 574 foreach ($this->_formContents as $formContent) {
540 575 if (Helpers::property_exists_nested($formContent, 'workFlowExist->oninput', true)) {
541 - $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['conditionalLogic'];
576 + $fileArr = ScriptFilePriorityManager::validationScriptFile()['conditionalLogic'];
542 577 $this->addScriptInLoadedScriptsList($fileArr);
543 - $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['resetPlaceholders'];
578 + $fileArr = ScriptFilePriorityManager::validationScriptFile()['validateFocusLost'];
544 579 $this->addScriptInLoadedScriptsList($fileArr);
545 - $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['bfResetDefaultValue'];
546 - $this->addScriptInLoadedScriptsList($fileArr);
547 - $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['validateFocusLost'];
548 - $this->addScriptInLoadedScriptsList($fileArr);
549 580 $fileArr = ScriptFilePriorityManager::frontendScriptFile()['observeElm'];
550 581 $this->addScriptInLoadedScriptsList($fileArr);
551 582 }
552 583 if (Helpers::property_exists_nested($formContent, 'additional->enabled->validateFocusLost', true)) {
553 - $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['validateFocusLost'];
584 + $fileArr = ScriptFilePriorityManager::validationScriptFile()['validateFocusLost'];
554 585 $this->addScriptInLoadedScriptsList($fileArr);
555 586 }
556 587 }
557 588 }
@@ -558,29 +589,12 @@
558 589
559 590 private function jsHiddenFieldScript()
560 591 {
561 592 $appConfig = get_option('bitform_app_config');
562 - $cacheTokenEnabled = true;
563 - if (is_object($appConfig) && property_exists($appConfig, 'cache_plugin')) {
564 - $cacheTokenEnabled = (bool) $appConfig->cache_plugin;
565 - } elseif (is_array($appConfig) && array_key_exists('cache_plugin', $appConfig)) {
566 - $cacheTokenEnabled = (bool) $appConfig['cache_plugin'];
567 - }
568 - if ($cacheTokenEnabled) {
593 + if (Helpers::property_exists_nested($appConfig, 'cache_plugin', true)) {
569 594 $fileArr = ScriptFilePriorityManager::frontendScriptFile()['hidden-token-field'];
570 595 $this->addScriptInLoadedScriptsList($fileArr);
571 596 return;
572 - }
573 - }
574 -
575 - private function jsRecaptchaV3Scripts()
576 - {
577 - foreach ($this->_formContents as $content) {
578 - if (isset($content->additional->enabled->recaptchav3) && $content->additional->enabled->recaptchav3) {
579 - $this->addScriptInLoadedScriptsList(['priority' => 302, 'filename' => 'scriptLoader.min.js']);
580 - $this->addScriptInLoadedScriptsList(['priority' => 303, 'filename' => 'initRecaptchaV3Fld.min.js']);
581 - return;
582 - }
583 597 }
584 598 }
585 599
586 600 public function dd($data, $exit = false)