PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.17
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | js/formidable.js +799 -1830 6.315.0.17 View file →
@@ -1,58 +1,53 @@
1 -/* exported frmRecaptcha, frmAfterRecaptcha */
1 +/* exported frmRecaptcha, frmAfterRecaptcha, frmUpdateField, frmDeleteEntry, frmOnSubmit, frm_resend_email */
2 2
3 +var frmFrontForm;
4 +
3 5 function frmFrontFormJS() {
4 6 'use strict';
5 7
6 - let jsErrors = [];
8 + /*global jQuery:false, frm_js, grecaptcha, frmProForm, tinyMCE */
9 + /*global frmThemeOverride_jsErrors, frmThemeOverride_frmPlaceError, frmThemeOverride_frmAfterSubmit */
7 10
8 - /**
9 - * Triggers custom JS event.
10 - *
11 - * @since 5.5.3
12 - *
13 - * @param {HTMLElement} el The HTML element.
14 - * @param {string} eventName Event name.
15 - * @param {*} data The passed data.
16 - */
17 - function triggerCustomEvent( el, eventName, data ) {
18 - if ( typeof window.CustomEvent !== 'function' ) {
19 - return;
20 - }
11 + var action = '';
12 + var jsErrors = [];
21 13
22 - const event = new CustomEvent( eventName );
23 - event.frmData = data;
14 + function maybeShowLabel() {
15 + /*jshint validthis:true */
16 + var $field = jQuery( this ),
17 + $label = $field.closest( '.frm_inside_container' ).find( '.frm_primary_label' ),
18 + val = $field.val();
24 19
25 - el.dispatchEvent( event );
20 + if ( val !== null && val.length > 0 ) {
21 + $label.addClass( 'frm_visible' );
22 + } else {
23 + $label.removeClass( 'frm_visible' );
24 + }
26 25 }
27 26
28 - /**
29 - * Get the ID of the field that changed.
30 - *
31 - * @param {HTMLElement|jQuery} field
32 - * @param {boolean} fullID
33 - * @return {string|number} Field ID.
34 - */
27 + /* Get the ID of the field that changed*/
35 28 function getFieldId( field, fullID ) {
36 - let nameParts;
37 - let fieldId;
38 - let isRepeating = false;
39 - let fieldName = '';
40 -
29 + var nameParts, fieldId,
30 + isRepeating = false,
31 + fieldName = '';
41 32 if ( field instanceof jQuery ) {
42 - field = field.get( 0 );
33 + fieldName = field.attr( 'name' );
34 + } else {
35 + fieldName = field.name;
43 36 }
44 37
45 - fieldName = field.name;
46 -
47 - if ( fieldName === undefined ) {
38 + if ( typeof fieldName === 'undefined' ) {
48 39 fieldName = '';
49 40 }
50 41
51 42 if ( fieldName === '' ) {
52 - fieldName = field.getAttribute( 'data-name' );
43 + if ( field instanceof jQuery ) {
44 + fieldName = field.data( 'name' );
45 + } else {
46 + fieldName = field.getAttribute( 'data-name' );
47 + }
53 48
54 - if ( fieldName === undefined ) {
49 + if ( typeof fieldName === 'undefined' ) {
55 50 fieldName = '';
56 51 }
57 52
58 53 if ( fieldName !== '' && fieldName ) {
@@ -67,24 +62,25 @@
67 62 return 0;
68 63 }
69 64 nameParts = nameParts.filter( function( n ) {
70 65 return n !== '';
71 - } );
66 + });
72 67
73 - fieldId = nameParts[ 0 ];
68 + fieldId = nameParts[0];
74 69
75 70 if ( nameParts.length === 1 ) {
76 71 return fieldId;
77 72 }
78 73
79 - if ( nameParts[ 1 ] === '[form' || nameParts[ 1 ] === '[row_ids' ) {
74 + if ( nameParts[1] === '[form' || nameParts[1] === '[row_ids' ) {
80 75 return 0;
81 76 }
82 77
83 78 // Check if 'this' is in a repeating section
84 - if ( document.querySelector( `input[name="item_meta[${ fieldId }][form]"]` ) ) {
79 + if ( jQuery( 'input[name="item_meta[' + fieldId + '][form]"]' ).length ) {
80 +
85 81 // this is a repeatable section with name: item_meta[repeating-section-id][row-id][field-id]
86 - fieldId = nameParts[ 2 ].replace( '[', '' );
82 + fieldId = nameParts[2].replace( '[', '' );
87 83 isRepeating = true;
88 84 }
89 85
90 86 // Check if 'this' is an other text field and get field ID for it
@@ -90,21 +86,21 @@
90 86 // Check if 'this' is an other text field and get field ID for it
91 87 if ( 'other' === fieldId ) {
92 88 if ( isRepeating ) {
93 89 // name for other fields: item_meta[370][0][other][414]
94 - fieldId = nameParts[ 3 ].replace( '[', '' );
90 + fieldId = nameParts[3].replace( '[', '' );
95 91 } else {
96 92 // Other field name: item_meta[other][370]
97 - fieldId = nameParts[ 1 ].replace( '[', '' );
93 + fieldId = nameParts[1].replace( '[', '' );
98 94 }
99 95 }
100 96
101 97 if ( fullID === true ) {
102 98 // For use in the container div id
103 - if ( fieldId === nameParts[ 0 ] ) {
104 - fieldId = `${ fieldId }-${ nameParts[ 1 ].replace( '[', '' ) }`;
99 + if ( fieldId === nameParts[0]) {
100 + fieldId = fieldId + '-' + nameParts[1].replace( '[', '' );
105 101 } else {
106 - fieldId = `${ fieldId }-${ nameParts[ 0 ] }-${ nameParts[ 1 ].replace( '[', '' ) }`;
102 + fieldId = fieldId + '-' + nameParts[0] + '-' + nameParts[1].replace( '[', '' );
107 103 }
108 104 }
109 105
110 106 return fieldId;
@@ -114,18 +110,12 @@
114 110 * Disable the submit button for a given jQuery form object
115 111 *
116 112 * @since 2.03.02
117 113 *
118 - * @param {Object} $form
119 - */
114 + * @param {object} $form
115 + */
120 116 function disableSubmitButton( $form ) {
121 - const form = $form instanceof jQuery ? $form.get( 0 ) : $form;
122 - if ( ! form ) {
123 - return;
124 - }
125 - form.querySelectorAll( 'input[type="submit"], input[type="button"], button[type="submit"], button.frm_save_draft' ).forEach(
126 - button => button.disabled = true
127 - );
117 + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).attr( 'disabled', 'disabled' );
128 118 }
129 119
130 120 /**
131 121 * Enable the submit button for a given jQuery form object
@@ -131,16 +121,12 @@
131 121 * Enable the submit button for a given jQuery form object
132 122 *
133 123 * @since 2.03.02
134 124 *
135 - * @param {HTMLElement} form
136 - *
137 - * @return {void}
138 - */
139 - function enableSubmitButton( form ) {
140 - form.querySelectorAll( 'input[type="submit"], input[type="button"], button[type="submit"]' ).forEach(
141 - button => button.disabled = false
142 - );
125 + * @param {object} $form
126 + */
127 + function enableSubmitButton( $form ) {
128 + $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).prop( 'disabled', false );
143 129 }
144 130
145 131 /**
146 132 * Disable the save draft link for a given jQuery form object
@@ -146,244 +132,136 @@
146 132 * Disable the save draft link for a given jQuery form object
147 133 *
148 134 * @since 4.04.03
149 135 *
150 - * @param {Object} $form
136 + * @param {object} $form
151 137 */
152 138 function disableSaveDraft( $form ) {
153 - const form = $form instanceof jQuery ? $form.get( 0 ) : $form;
154 - if ( ! form ) {
155 - return;
156 - }
157 - form.querySelectorAll( 'a.frm_save_draft' ).forEach(
158 - link => link.style.pointerEvents = 'none'
159 - );
139 + $form.find( 'a.frm_save_draft' ).css( 'pointer-events', 'none' );
160 140 }
161 141
162 142 /**
163 - * Enable the save draft link for a given form object.
143 + * Enable the save draft link for a given jQuery form object
164 144 *
165 145 * @since 4.04.03
166 146 *
167 - * @param {jQuery|HTMLElement} $form
147 + * @param {object} $form
168 148 */
169 149 function enableSaveDraft( $form ) {
170 - const form = $form instanceof jQuery ? $form.get( 0 ) : $form;
171 - if ( ! form ) {
172 - return;
173 - }
174 - form.querySelectorAll( '.frm_save_draft' ).forEach( saveDraftButton => {
175 - saveDraftButton.disabled = false;
176 - saveDraftButton.style.pointerEvents = '';
177 - } );
150 + $form.find( 'a.frm_save_draft' ).css( 'pointer-events', '' );
178 151 }
179 152
180 - /**
181 - * Validate form with JS.
182 - *
183 - * @param {HTMLElement|jQuery} object
184 - * @return {Array} Errors.
185 - */
186 153 function validateForm( object ) {
187 - let errors = [];
154 + var r, rl, n, nl, fields, field, value, requiredFields,
155 + errors = [];
188 156
189 - const vanillaJsObject = 'function' === typeof object.get ? object.get( 0 ) : object;
190 -
191 - // Required field validation.
192 - vanillaJsObject?.querySelectorAll( '.frm_required_field' ).forEach(
193 - requiredField => {
194 - const isVisible = requiredField.offsetParent !== null;
195 - if ( ! isVisible ) {
196 - return;
157 + // Make sure required text field is filled in
158 + requiredFields = jQuery( object ).find(
159 + '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea'
160 + ).filter( ':not(.frm_optional)' );
161 + if ( requiredFields.length ) {
162 + for ( r = 0, rl = requiredFields.length; r < rl; r++ ) {
163 + if ( hasClass( requiredFields[r], 'ed_button' ) ) {
164 + // skip rich text field buttons.
165 + continue;
197 166 }
198 -
199 - requiredField.querySelectorAll( 'input, select, textarea' ).forEach(
200 - requiredInput => {
201 - if ( hasClass( requiredInput, 'frm_optional' ) || hasClass( requiredInput, 'ed_button' ) ) {
202 - // skip rich text field buttons.
203 - return;
204 - }
205 -
206 - errors = checkRequiredField( requiredInput, errors );
207 - }
208 - );
167 + errors = checkRequiredField( requiredFields[r], errors );
209 168 }
210 - );
169 + }
211 170
212 - vanillaJsObject?.querySelectorAll( 'input,select,textarea' ).forEach(
213 - field => {
214 - if ( '' === field.value ) {
215 - if ( 'number' === field.type ) {
216 - // A number field will return an empty string when it is invalid.
217 - checkValidity( field, errors );
171 + fields = jQuery( object ).find( 'input,select,textarea' );
172 + if ( fields.length ) {
173 + for ( n = 0, nl = fields.length; n < nl; n++ ) {
174 + field = fields[n];
175 + value = field.value;
176 + if ( value !== '' ) {
177 + if ( field.type === 'hidden' ) {
178 + // don't validate
179 + } else if ( field.type === 'number' ) {
180 + errors = checkNumberField( field, errors );
181 + } else if ( field.type === 'email' ) {
182 + errors = checkEmailField( field, errors );
183 + } else if ( field.type === 'password' ) {
184 + errors = checkPasswordField( field, errors );
185 + } else if ( field.type === 'url' ) {
186 + errors = checkUrlField( field, errors );
187 + } else if ( field.pattern !== null ) {
188 + errors = checkPatternField( field, errors );
218 189 }
219 -
220 - const isConfirmationField = field.name && 0 === field.name.indexOf( 'item_meta[conf_' );
221 - if ( ! isConfirmationField ) {
222 - // Allow a blank confirmation field to still call validateFieldValue.
223 - // If we continue for a confirmation field there are issues with forms submitting with a blank confirmation field.
224 - return;
225 - }
226 190 }
227 -
228 - validateFieldValue( field, errors, true );
229 - checkValidity( field, errors );
230 191 }
231 - );
192 + }
232 193
233 - // Invisible captchas are processed after validation.
234 - // We only want to validate a visible captcha on submit.
235 - if ( ! hasInvisibleRecaptcha( object ) ) {
236 - errors = validateRecaptcha( object, errors );
237 - }
194 + errors = validateRecaptcha( object, errors );
238 195
239 196 return errors;
240 197 }
241 198
242 199 /**
243 - * Check the ValidityState interface for the field.
244 - * If it is invalid, show an error for it.
245 - *
246 - * @param {HTMLElement} field
247 - * @param {Array} errors
248 - * @return {void}
249 - */
250 - function checkValidity( field, errors ) {
251 - if ( 'object' !== typeof field.validity || false !== field.validity.valid ) {
252 - return;
253 - }
254 -
255 - const fieldID = getFieldId( field, true );
256 - if ( errors[ fieldID ] === undefined ) {
257 - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
258 - }
259 -
260 - if ( 'function' === typeof field.reportValidity ) {
261 - // This triggers an error pop up.
262 - field.reportValidity();
263 - }
264 - }
265 -
266 - /**
267 200 * @since 5.0.10
268 201 *
269 - * @param {Object} element
202 + * @param {object} element
270 203 * @param {string} targetClass
271 - * @return {boolean} True if the element has the target class.
204 + * @returns {boolean}
272 205 */
273 206 function hasClass( element, targetClass ) {
274 - return element.classList && element.classList.contains( targetClass );
207 + var className = ' ' + element.className + ' ';
208 + return -1 !== className.indexOf( ' ' + targetClass + ' ' );
275 209 }
276 210
277 - /**
278 - * @param {HTMLElement} field
279 - */
280 211 function maybeValidateChange( field ) {
281 212 if ( field.type === 'url' ) {
282 - maybeAddHttpsToUrl( field );
213 + maybeAddHttpToUrl( field );
283 214 }
284 - const form = field.closest( 'form' );
285 - if ( form && hasClass( form, 'frm_js_validate' ) ) {
215 + if ( jQuery( field ).closest( 'form' ).hasClass( 'frm_js_validate' ) ) {
286 216 validateField( field );
287 217 }
288 218 }
289 219
290 - /**
291 - * @param {HTMLElement} field
292 - */
293 - function maybeAddHttpsToUrl( field ) {
294 - const url = field.value;
295 - const matches = url.match( /^(https?|ftps?|mailto|news|feed|telnet):/ );
220 + function maybeAddHttpToUrl( field ) {
221 + var url = field.value;
222 + var matches = url.match( /^(https?|ftps?|mailto|news|feed|telnet):/ );
296 223 if ( field.value !== '' && matches === null ) {
297 - field.value = `https://${ url }`;
224 + field.value = 'http://' + url;
298 225 }
299 226 }
300 227
301 - /**
302 - * Validate a field with JS.
303 - *
304 - * @param {HTMLElement} field
305 - *
306 - * @return {void}
307 - */
308 228 function validateField( field ) {
309 - let errors;
310 - let key;
229 + var key,
230 + errors = [],
231 + $fieldCont = jQuery( field ).closest( '.frm_form_field' );
311 232
312 - errors = [];
313 - const fieldContainer = field.closest( '.frm_form_field' );
314 -
315 - if ( ! fieldContainer ) {
316 - // Hidden fields do not have a field container and do not require JS validation.
317 - return;
318 - }
319 -
320 - if ( hasClass( fieldContainer, 'frm_required_field' ) && ! hasClass( field, 'frm_optional' ) ) {
233 + if ( $fieldCont.hasClass( 'frm_required_field' ) && ! jQuery( field ).hasClass( 'frm_optional' ) ) {
321 234 errors = checkRequiredField( field, errors );
322 235 }
323 236
324 237 if ( errors.length < 1 ) {
325 - validateFieldValue( field, errors, false );
238 + if ( field.type === 'email' ) {
239 + errors = checkEmailField( field, errors );
240 + } else if ( field.type === 'password' ) {
241 + errors = checkPasswordField( field, errors );
242 + } else if ( field.type === 'number' ) {
243 + errors = checkNumberField( field, errors );
244 + } else if ( field.type === 'url' ) {
245 + errors = checkUrlField( field, errors );
246 + } else if ( field.pattern !== null ) {
247 + errors = checkPatternField( field, errors );
248 + }
326 249 }
327 250
328 - removeFieldError( fieldContainer );
329 - if ( Object.keys( errors ).length > 0 ) {
251 + removeFieldError( $fieldCont );
252 + if ( Object.keys( errors ).length > 0 ) {
330 253 for ( key in errors ) {
331 - addFieldError( fieldContainer, key, errors );
254 + addFieldError( $fieldCont, key, errors );
332 255 }
333 256 }
334 257 }
335 258
336 - /**
337 - * Validates a field value.
338 - *
339 - * @since 6.15 Added `onSubmit` parameter.
340 - *
341 - * @param {HTMLElement} field Field input.
342 - * @param {Object} errors Errors data.
343 - * @param {boolean} onSubmit Is `true` if the form is being submitted.
344 - */
345 - function validateFieldValue( field, errors, onSubmit ) {
346 - if ( field.type === 'hidden' ) {
347 - // don't validate
348 - } else if ( field.type === 'number' ) {
349 - checkNumberField( field, errors );
350 - } else if ( field.type === 'email' ) {
351 - checkEmailField( field, errors, onSubmit );
352 - } else if ( field.type === 'password' ) {
353 - checkPasswordField( field, errors, onSubmit );
354 - } else if ( field.type === 'url' ) {
355 - checkUrlField( field, errors );
356 - } else if ( field.pattern !== null ) {
357 - checkPatternField( field, errors );
358 - }
359 -
360 - if ( 'tel' === field.type && shouldCheckConfirmField( field, onSubmit ) ) {
361 - confirmField( field, errors );
362 - }
363 -
364 - /**
365 - * @since 6.15 Added `onSubmit` to the data.
366 - */
367 - triggerCustomEvent( document, 'frm_validate_field_value', {
368 - field,
369 - errors,
370 - onSubmit
371 - } );
372 - }
373 -
374 - /**
375 - * @param {HTMLElement} field
376 - * @param {Array} errors
377 - * @return {Array} Errors
378 - */
379 259 function checkRequiredField( field, errors ) {
380 - let tempVal;
381 - let i;
382 - let placeholder;
383 - let val = '';
384 - let fieldID = '';
385 - let fileID = field.getAttribute( 'data-frmfile' );
260 + var checkGroup, tempVal, i, placeholder,
261 + val = '',
262 + fieldID = '',
263 + fileID = field.getAttribute( 'data-frmfile' );
386 264
387 265 if ( field.type === 'hidden' && fileID === null && ! isAppointmentField( field ) && ! isInlineDatepickerField( field ) ) {
388 266 return errors;
389 267 }
@@ -388,26 +266,19 @@
388 266 return errors;
389 267 }
390 268
391 269 if ( field.type === 'checkbox' || field.type === 'radio' ) {
392 - document.querySelectorAll( `input[name="${ field.name }"]` ).forEach( function( input ) {
393 - const requiredField = input.closest( '.frm_required_field' );
394 - if ( ! requiredField ) {
395 - return;
396 - }
397 -
398 - const checkedInputs = requiredField.querySelectorAll( 'input:checked' );
399 - checkedInputs.forEach( function( checkedInput ) {
400 - val = checkedInput.value;
401 - } );
402 - } );
270 + checkGroup = jQuery( 'input[name="' + field.name + '"]' ).closest( '.frm_required_field' ).find( 'input:checked' );
271 + jQuery( checkGroup ).each( function() {
272 + val = this.value;
273 + });
403 274 } else if ( field.type === 'file' || fileID ) {
404 - if ( fileID === undefined ) {
275 + if ( typeof fileID === 'undefined' ) {
405 276 fileID = getFieldId( field, true );
406 277 fileID = fileID.replace( 'file', '' );
407 278 }
408 279
409 - if ( errors[ fileID ] === undefined ) {
280 + if ( typeof errors[ fileID ] === 'undefined' ) {
410 281 val = getFileVals( fileID );
411 282 }
412 283 fieldID = fileID;
413 284 } else {
@@ -415,10 +286,9 @@
415 286 // skip hidden other fields
416 287 return errors;
417 288 }
418 289
419 - val = jQuery( field ).val(); // eslint-disable-line no-jquery/no-val
420 -
290 + val = jQuery( field ).val();
421 291 if ( val === null ) {
422 292 val = '';
423 293 } else if ( typeof val !== 'string' ) {
424 294 tempVal = val;
@@ -423,10 +293,10 @@
423 293 } else if ( typeof val !== 'string' ) {
424 294 tempVal = val;
425 295 val = '';
426 296 for ( i = 0; i < tempVal.length; i++ ) {
427 - if ( tempVal[ i ] !== '' ) {
428 - val = tempVal[ i ];
297 + if ( tempVal[i] !== '' ) {
298 + val = tempVal[i];
429 299 }
430 300 }
431 301 }
432 302
@@ -439,22 +309,14 @@
439 309 } else {
440 310 fieldID = getFieldId( field, true );
441 311 }
442 312
443 - // Make sure fieldID is a string.
444 - // fieldID may be a number which doesn't include a .replace function.
445 - if ( 'function' !== typeof fieldID.replace ) {
446 - fieldID = fieldID.toString();
447 - }
448 -
449 313 if ( hasClass( field, 'frm_time_select' ) ) {
450 314 // set id for time field
451 315 fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' );
452 316 } else if ( isSignatureField( field ) ) {
453 317 if ( val === '' ) {
454 - const fieldContainer = field.closest( '.frm_form_field' );
455 - const outputField = fieldContainer ? fieldContainer.querySelector( `[name="${ field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) }"]` ) : null;
456 - val = outputField ? outputField.value : '';
318 + val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val();
457 319 }
458 320 fieldID = fieldID.replace( '-typed', '' );
459 321 }
460 322
@@ -475,57 +337,36 @@
475 337
476 338 return errors;
477 339 }
478 340
479 - /**
480 - * @param {HTMLElement} field
481 - * @return {boolean} True if the input is a typed signature input.
482 - */
483 341 function isSignatureField( field ) {
484 - const name = field.getAttribute( 'name' );
342 + var name = field.getAttribute( 'name' );
485 343 return 'string' === typeof name && '[typed]' === name.substr( -7 );
486 344 }
487 345
488 - /**
489 - * @param {HTMLElement} field
490 - * @return {boolean} True if the field is a SSA appointment field.
491 - */
492 346 function isAppointmentField( field ) {
493 347 return hasClass( field, 'ssa_appointment_form_field_appointment_id' );
494 348 }
495 349
496 - /**
497 - * @param {HTMLElement} field
498 - * @return {boolean} True if the field is inline datepicker field.
499 - */
500 350 function isInlineDatepickerField( field ) {
501 351 return 'hidden' === field.type && '_alt' === field.id.substr( -4 ) && hasClass( field.nextElementSibling, 'frm_date_inline' );
502 352 }
503 353
504 - /**
505 - * @param {string|number} fileID
506 - * @return {string} File input value.
507 - */
508 354 function getFileVals( fileID ) {
509 - let val = '';
510 - const fileFields = document.querySelectorAll( `input[name="file${ fileID }"], input[name="file${ fileID }[]"], input[name^="item_meta[${ fileID }]"]` );
355 + var val = '',
356 + fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' );
511 357
512 - fileFields.forEach( function( field ) {
358 + fileFields.each( function() {
513 359 if ( val === '' ) {
514 - val = field.value;
360 + val = this.value;
515 361 }
516 - } );
362 + });
517 363 return val;
518 364 }
519 365
520 - /**
521 - * @param {HTMLElement} field
522 - * @param {Array} errors
523 - * @return {void}
524 - */
525 366 function checkUrlField( field, errors ) {
526 - let fieldID;
527 - const url = field.value;
367 + var fieldID,
368 + url = field.value;
528 369
529 370 if ( url !== '' && ! /^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i.test( url ) ) {
530 371 fieldID = getFieldId( field, true );
531 372 if ( ! ( fieldID in errors ) ) {
@@ -531,92 +372,46 @@
531 372 if ( ! ( fieldID in errors ) ) {
532 373 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
533 374 }
534 375 }
376 + return errors;
535 377 }
536 378
537 - /**
538 - * Checks if the confirm field should be checked.
539 - *
540 - * @since 6.15
541 - *
542 - * @param {HTMLElement} field Field input.
543 - * @param {boolean} onSubmit Is `true` if the form is being submitted.
544 - * @return {boolean} True if we should confirm the field.
545 - */
546 - function shouldCheckConfirmField( field, onSubmit ) {
547 - if ( onSubmit ) {
548 - // Always check on submitting.
549 - return true;
550 - }
379 + function checkEmailField( field, errors ) {
380 + var fieldID = getFieldId( field, true ),
381 + pattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
551 382
552 - if ( 0 === field.id.indexOf( 'field_conf_' ) ) {
553 - // Always check if it's the confirm field.
554 - return true;
555 - }
556 -
557 - return false;
558 - }
559 -
560 - /**
561 - * Check the email field for errors.
562 - *
563 - * @since 6.15 Added `onSubmit` parameter.
564 - *
565 - * @param {HTMLElement} field Field input.
566 - * @param {Object} errors Errors data.
567 - * @param {boolean} onSubmit Is `true` if the form is being submitted.
568 - */
569 - function checkEmailField( field, errors, onSubmit ) {
570 - const fieldID = getFieldId( field, true );
571 - const pattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
572 -
573 383 // validate the current field we're editing first
574 384 if ( '' !== field.value && pattern.test( field.value ) === false ) {
575 385 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
576 386 }
577 387
578 - if ( shouldCheckConfirmField( field, onSubmit ) ) {
579 - confirmField( field, errors );
580 - }
388 + confirmField( field, errors );
389 + return errors;
581 390 }
582 391
583 - /**
584 - * Check the password field for errors.
585 - *
586 - * @since 6.15 Added `onSubmit` parameter.
587 - *
588 - * @param {HTMLElement} field Field input.
589 - * @param {Object} errors Errors data.
590 - * @param {boolean} onSubmit Is `true` if the form is being submitted.
591 - */
592 - function checkPasswordField( field, errors, onSubmit ) {
593 - if ( shouldCheckConfirmField( field, onSubmit ) ) {
594 - confirmField( field, errors );
595 - }
392 + function checkPasswordField( field, errors ) {
393 + confirmField( field, errors );
394 + return errors;
596 395 }
597 396
598 - /**
599 - * @param {HTMLElement} field
600 - * @param {Array} errors
601 - * @return {void}
602 - */
603 397 function confirmField( field, errors ) {
604 - const fieldID = getFieldId( field, true );
605 - const strippedId = field.id.replace( 'conf_', '' );
606 - const strippedFieldID = fieldID.replace( 'conf_', '' );
607 - const confirmField = document.getElementById( strippedId.replace( 'field_', 'field_conf_' ) );
398 + var value, confirmValue, firstField,
399 + fieldID = getFieldId( field, true ),
400 + strippedId = field.id.replace( 'conf_', '' ),
401 + strippedFieldID = fieldID.replace( 'conf_', '' ),
402 + confirmField = document.getElementById( strippedId.replace( 'field_', 'field_conf_' ) );
608 403
609 - if ( ! confirmField || errors[ `conf_${ strippedFieldID }` ] !== undefined ) {
404 + if ( confirmField === null || typeof errors[ 'conf_' + strippedFieldID ] !== 'undefined' ) {
610 405 return;
611 406 }
612 407
613 408 if ( fieldID !== strippedFieldID ) {
614 - const firstField = document.getElementById( strippedId );
615 - const { value } = firstField;
616 - const confirmValue = confirmField.value;
617 - if ( value !== confirmValue ) {
618 - errors[ `conf_${ strippedFieldID }` ] = getFieldValidationMessage( confirmField, 'data-confmsg' );
409 + firstField = document.getElementById( strippedId );
410 + value = firstField.value;
411 + confirmValue = confirmField.value;
412 + if ( '' !== value && '' !== confirmValue && value !== confirmValue ) {
413 + errors[ 'conf_' + strippedFieldID ] = getFieldValidationMessage( confirmField, 'data-confmsg' );
619 414 }
620 415 } else {
621 416 validateField( confirmField );
622 417 }
@@ -621,16 +416,11 @@
621 416 validateField( confirmField );
622 417 }
623 418 }
624 419
625 - /**
626 - * @param {HTMLElement} field
627 - * @param {Array} errors
628 - * @return {void}
629 - */
630 420 function checkNumberField( field, errors ) {
631 - let fieldID;
632 - const number = field.value;
421 + var fieldID,
422 + number = field.value;
633 423
634 424 if ( number !== '' && isNaN( number / 1 ) !== false ) {
635 425 fieldID = getFieldId( field, true );
636 426 if ( ! ( fieldID in errors ) ) {
@@ -636,200 +426,106 @@
636 426 if ( ! ( fieldID in errors ) ) {
637 427 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
638 428 }
639 429 }
430 + return errors;
640 431 }
641 432
642 - /**
643 - * @param {HTMLElement} field
644 - * @param {Array} errors
645 - * @return {void}
646 - */
647 433 function checkPatternField( field, errors ) {
648 - let fieldID;
649 - const text = field.value;
650 - let format = getFieldValidationMessage( field, 'pattern' );
434 + var fieldID,
435 + text = field.value,
436 + format = getFieldValidationMessage( field, 'pattern' );
651 437
652 438 if ( format !== '' && text !== '' ) {
653 439 fieldID = getFieldId( field, true );
654 440 if ( ! ( fieldID in errors ) ) {
655 - if ( 'object' === typeof window.frmProForm && 'function' === typeof window.frmProForm.isIntlPhoneInput && window.frmProForm.isIntlPhoneInput( field ) ) {
656 - if ( ! window.frmProForm.validateIntlPhoneInput( field ) ) {
657 - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
658 - }
659 - } else {
660 - format = new RegExp( `^${ format }$`, 'i' );
661 - if ( format.test( text ) === false ) {
662 - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
663 - }
441 + format = new RegExp( '^' + format + '$', 'i' );
442 + if ( format.test( text ) === false ) {
443 + errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
664 444 }
665 445 }
666 446 }
447 + return errors;
667 448 }
668 449
669 - /**
670 - * Set color for select placeholders.
671 - *
672 - * @since 6.5.1
673 - */
674 - function setSelectPlaceholderColor() {
675 - const selects = document.querySelectorAll( '.form-field select' );
676 - const styleElement = document.querySelector( '.with_frm_style' );
677 - const textColorDisabled = styleElement ? getComputedStyle( styleElement ).getPropertyValue( '--text-color-disabled' ).trim() : '';
678 - // Exit if there are no select elements or the textColorDisabled property is missing
679 - if ( ! selects.length || ! textColorDisabled ) {
680 - return;
681 - }
450 + function hasInvisibleRecaptcha( object ) {
451 + var recaptcha, recaptchaID, alreadyChecked;
682 452
683 - // Function to change the color of a select element
684 - const changeSelectColor = function( select ) {
685 - if ( select.options[ select.selectedIndex ] && hasClass( select.options[ select.selectedIndex ], 'frm-select-placeholder' ) ) {
686 - select.style.setProperty( 'color', textColorDisabled, 'important' );
687 - } else {
688 - select.style.color = '';
689 - }
690 - };
691 -
692 - // Use a loop to iterate through each select element
693 - Array.prototype.forEach.call( selects, function( select ) {
694 - // Apply the color change to each select element
695 - changeSelectColor( select );
696 -
697 - // Add an event listener for future changes
698 - select.addEventListener( 'change', function() {
699 - changeSelectColor( select );
700 - } );
701 - } );
702 - }
703 -
704 - /**
705 - * @param {HTMLElement|jQuery} object
706 - *
707 - * @return {HTMLElement|false} Captcha element if there is an invisible recaptcha.
708 - */
709 - function hasInvisibleRecaptcha( object ) {
710 453 if ( isGoingToPrevPage( object ) ) {
711 454 return false;
712 455 }
713 456
714 - const form = object instanceof jQuery ? object.get( 0 ) : object;
715 - if ( ! form ) {
716 - return false;
717 - }
718 -
719 - const recaptcha = form.querySelector( '.frm-g-recaptcha[data-size="invisible"], .g-recaptcha[data-size="invisible"]' );
720 - if ( recaptcha ) {
721 - const recaptchaID = recaptcha.dataset.rid;
722 - const alreadyChecked = grecaptcha.getResponse( recaptchaID );
457 + recaptcha = jQuery( object ).find( '.frm-g-recaptcha[data-size="invisible"], .g-recaptcha[data-size="invisible"]' );
458 + if ( recaptcha.length ) {
459 + recaptchaID = recaptcha.data( 'rid' );
460 + alreadyChecked = grecaptcha.getResponse( recaptchaID );
723 461 if ( alreadyChecked.length === 0 ) {
724 462 return recaptcha;
463 + } else {
464 + return false;
725 465 }
466 + } else {
467 + return false;
726 468 }
727 -
728 - return false;
729 469 }
730 470
731 - /**
732 - * @param {HTMLElement} invisibleRecaptcha
733 - *
734 - * @return {void}
735 - */
736 471 function executeInvisibleRecaptcha( invisibleRecaptcha ) {
737 - const recaptchaID = invisibleRecaptcha.dataset.rid;
472 + var recaptchaID = invisibleRecaptcha.data( 'rid' );
738 473 grecaptcha.reset( recaptchaID );
739 474 grecaptcha.execute( recaptchaID );
740 475 }
741 476
742 477 function validateRecaptcha( form, errors ) {
743 - const formEl = form instanceof jQuery ? form.get( 0 ) : form;
744 - if ( ! formEl ) {
745 - return errors;
746 - }
478 + var recaptchaID, response, fieldContainer, fieldID,
479 + $recaptcha = jQuery( form ).find( '.frm-g-recaptcha' );
480 + if ( $recaptcha.length ) {
481 + recaptchaID = $recaptcha.data( 'rid' );
747 482
748 - const recaptcha = formEl.querySelector( '.frm-g-recaptcha' );
749 - if ( ! recaptcha ) {
750 - return errors;
751 - }
752 -
753 - const recaptchaID = recaptcha.dataset.rid;
754 - let response;
755 -
756 - try {
757 - response = grecaptcha.getResponse( recaptchaID );
758 - } catch ( e ) {
759 - if ( formEl.querySelector( 'input[name="recaptcha_checked"]' ) ) {
760 - return errors;
483 + try {
484 + response = grecaptcha.getResponse( recaptchaID );
485 + } catch ( e ) {
486 + if ( jQuery( form ).find( 'input[name="recaptcha_checked"]' ).length ) {
487 + return errors;
488 + } else {
489 + response = '';
490 + }
761 491 }
762 - response = '';
763 - }
764 492
765 - if ( response.length === 0 ) {
766 - const fieldContainer = recaptcha.closest( '.frm_form_field' );
767 - if ( fieldContainer?.id ) {
768 - const fieldID = fieldContainer.id.replace( 'frm_field_', '' ).replace( '_container', '' );
493 + if ( response.length === 0 ) {
494 + fieldContainer = $recaptcha.closest( '.frm_form_field' );
495 + fieldID = fieldContainer.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_container', '' );
769 496 errors[ fieldID ] = '';
770 497 }
771 498 }
772 -
773 499 return errors;
774 500 }
775 501
776 - /**
777 - * @param {HTMLElement} field
778 - * @param {string} messageType
779 - * @return {string} The error message to display.
780 - */
781 502 function getFieldValidationMessage( field, messageType ) {
782 - let msg = field.getAttribute( messageType );
503 + var msg, errorHtml;
504 +
505 + msg = field.getAttribute( messageType );
783 506 if ( null === msg ) {
784 507 msg = '';
785 508 }
786 509
787 510 if ( '' !== msg && shouldWrapErrorHtmlAroundMessageType( messageType ) ) {
788 - msg = wrapErrorHtml( msg, field );
511 + errorHtml = field.getAttribute( 'data-error-html' );
512 + if ( null !== errorHtml ) {
513 + errorHtml = errorHtml.replace( /\+/g, '%20' );
514 + msg = decodeURIComponent( errorHtml ).replace( '[error]', msg );
515 + msg = msg.replace( '[key]', getFieldId( field, false ) );
516 + }
789 517 }
790 518
791 519 return msg;
792 520 }
793 521
794 - /**
795 - * @param {string} msg
796 - * @param {HTMLElement} field
797 - * @return {string} The error HTML to use.
798 - */
799 - function wrapErrorHtml( msg, field ) {
800 - let errorHtml = field.getAttribute( 'data-error-html' );
801 - if ( null === errorHtml ) {
802 - return msg;
803 - }
804 -
805 - errorHtml = errorHtml.replace( /\+/g, '%20' );
806 - msg = decodeURIComponent( errorHtml ).replace( '[error]', msg );
807 - const fieldId = getFieldId( field, false );
808 - const split = fieldId.split( '-' );
809 - const fieldIdParts = field.id.split( '_' );
810 - fieldIdParts.shift(); // Drop the "field" value from the front.
811 - split[ 0 ] = fieldIdParts.join( '_' );
812 - const errorKey = split.join( '-' );
813 - return msg.replace( '[key]', errorKey );
814 - }
815 -
816 522 function shouldWrapErrorHtmlAroundMessageType( type ) {
817 523 return 'pattern' !== type;
818 524 }
819 525
820 - /**
821 - * Check if JS validation should happen.
822 - *
823 - * @param {HTMLElement|Object} object Form object.
824 - * @return {boolean} True if validation is enabled and we are not saving a draft or going to a previous page.
825 - */
826 526 function shouldJSValidate( object ) {
827 - if ( 'function' === typeof object.get ) {
828 - // Get the HTMLElement from a jQuery object.
829 - object = object.get( 0 );
830 - }
831 - let validate = hasClass( object, 'frm_js_validate' );
527 + var validate = jQuery( object ).hasClass( 'frm_js_validate' );
832 528 if ( validate && typeof frmProForm !== 'undefined' && ( frmProForm.savingDraft( object ) || frmProForm.goingToPreviousPage( object ) ) ) {
833 529 validate = false;
834 530 }
835 531
@@ -835,47 +531,28 @@
835 531
836 532 return validate;
837 533 }
838 534
839 - /**
840 - * @param {HTMLElement} object
841 - * @param {string} action
842 - * @return {void}
843 - */
844 535 function getFormErrors( object, action ) {
845 - const fieldsets = object.querySelectorAll( '.frm_form_field' );
846 - fieldsets.forEach( field => field.classList.add( 'frm_doing_ajax' ) );
536 + var fieldset;
847 537
848 - const data = `${ jQuery( object ).serialize() }&action=frm_entries_${ action }&nonce=${ frm_js.nonce }`; // eslint-disable-line no-jquery/no-serialize
849 - const shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' );
538 + if ( typeof action === 'undefined' ) {
539 + jQuery( object ).find( 'input[name="frm_action"]' ).val();
540 + }
850 541
851 - const doRedirect = response => {
852 - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ] );
542 + fieldset = jQuery( object ).find( '.frm_form_field' );
543 + fieldset.addClass( 'frm_doing_ajax' );
544 + jQuery.ajax({
545 + type: 'POST', url: frm_js.ajax_url,
546 + data: jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce,
547 + success: function( response ) {
548 + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
549 + $fieldCont, key, inCollapsedSection, frmTrigger,
550 + defaultResponse = { 'content': '', 'errors': {}, 'pass': false };
551 + if ( response === null ) {
552 + response = defaultResponse;
553 + }
853 554
854 - if ( ! response.openInNewTab ) {
855 - // We return here because we're redirecting there is no need to update content.
856 - window.location = response.redirect;
857 - return;
858 - }
859 -
860 - // We don't return here because we're opening in a new tab, the old tab will still update.
861 - const newTab = window.open( response.redirect, '_blank' );
862 - if ( ! newTab && response.fallbackMsg && response.content ) {
863 - response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ` ${ response.fallbackMsg }</div></div>` );
864 - }
865 - };
866 -
867 - const success = function( response ) {
868 - const defaultResponse = {
869 - content: '',
870 - errors: {},
871 - pass: false
872 - };
873 -
874 - if ( response === null ) {
875 - response = defaultResponse;
876 - } else {
877 - // Response is a string. Convert it to an object.
878 555 response = response.replace( /^\s+|\s+$/g, '' );
879 556 if ( response.indexOf( '{' ) === 0 ) {
880 557 response = JSON.parse( response );
881 558 } else {
@@ -880,222 +557,151 @@
880 557 response = JSON.parse( response );
881 558 } else {
882 559 response = defaultResponse;
883 560 }
884 - }
885 561
886 - let willRedirect = false;
562 + if ( typeof response.redirect !== 'undefined' ) {
563 + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
564 + window.location = response.redirect;
565 + } else if ( response.content !== '' ) {
566 + // the form or success message was returned
887 567
888 - if ( response.redirect !== undefined ) {
889 - if ( shouldTriggerEvent ) {
890 - triggerCustomEvent( object, 'frmSubmitEvent' );
891 - return;
892 - }
568 + removeSubmitLoading( jQuery( object ) );
569 + if ( frm_js.offset != -1 ) {
570 + frmFrontForm.scrollMsg( jQuery( object ), false );
571 + }
572 + formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
573 + response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
574 + replaceContent = jQuery( object ).closest( '.frm_forms' );
575 + removeAddedScripts( replaceContent, formID );
576 + delay = maybeSlideOut( replaceContent, response.content );
893 577
894 - if ( response.delay ) {
895 - setTimeout( function() {
896 - doRedirect( response );
897 - }, 1000 * response.delay );
898 - } else {
899 - doRedirect( response );
900 - }
578 + setTimeout(
579 + function() {
580 + var container, input, previousInput;
901 581
902 - willRedirect = true;
903 - }
582 + replaceContent.replaceWith( response.content );
904 583
905 - if ( 'string' === typeof response.content && response.content !== '' ) {
906 - // the form or success message was returned
584 + addUrlParam( response );
907 585
908 - if ( shouldTriggerEvent ) {
909 - triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content } );
910 - return;
911 - }
586 + if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase
587 + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val();
588 + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val();
589 + frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
590 + }
912 591
913 - removeSubmitLoading( jQuery( object ) );
914 - if ( frm_js.offset != -1 ) {
915 - frmFrontForm.scrollMsg( jQuery( object ), false );
916 - }
592 + if ( typeof response.recaptcha !== 'undefined' ) {
593 + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' );
594 + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">';
595 + previousInput = container.find( 'input[name="recaptcha_checked"]' );
917 596
918 - const formIdInput = object.querySelector( 'input[name="form_id"]' );
919 - const formID = formIdInput ? formIdInput.value : '';
920 - response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
921 - const replaceContent = jQuery( object ).closest( '.frm_forms' ); // eslint-disable-line no-jquery/no-closest
922 - removeAddedScripts( replaceContent, formID );
923 - const delay = maybeSlideOut( replaceContent, response.content );
597 + if ( previousInput.length ) {
598 + previousInput.replaceWith( input );
599 + } else {
600 + container.append( input );
601 + }
602 + }
924 603
925 - setTimeout(
926 - function() {
927 - afterFormSubmittedBeforeReplace( object, response );
604 + afterFormSubmitted( object, response );
605 + },
606 + delay
607 + );
608 + } else if ( Object.keys( response.errors ).length ) {
609 + // errors were returned
928 610
929 - replaceContent.replaceWith( response.content );
611 + removeSubmitLoading( jQuery( object ), 'enable' );
930 612
931 - addUrlParam( response );
613 + //show errors
614 + contSubmit = true;
615 + removeAllErrors();
932 616
933 - if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase
934 - const pageOrderInput = document.querySelector( `input[name="frm_page_order_${ formID }"]` );
935 - const pageOrder = pageOrderInput ? pageOrderInput.value : '';
936 - const tempDiv = document.createElement( 'div' );
937 - tempDiv.innerHTML = response.content;
938 - const formReturnedInput = tempDiv.querySelector( 'input[name="form_id"]' );
939 - const formReturned = formReturnedInput ? formReturnedInput.value : '';
940 - frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
941 - }
617 + $fieldCont = null;
942 618
943 - afterFormSubmitted( object, response );
944 - },
945 - delay
946 - );
947 - } else if ( response.errors !== undefined && Object.keys( response.errors ).length ) {
948 - // errors were returned
949 - removeSubmitLoading( jQuery( object ), 'enable' );
619 + for ( key in response.errors ) {
620 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
950 621
951 - //show errors
952 - let contSubmit = true;
953 - removeAllErrors();
954 -
955 - let $fieldCont = null;
956 -
957 - for ( const key in response.errors ) {
958 - const fieldContEl = object.querySelector( `#frm_field_${ key }_container` );
959 - $fieldCont = fieldContEl ? jQuery( fieldContEl ) : jQuery();
960 -
961 - if ( $fieldCont.length ) {
962 - if ( ! $fieldCont.is( ':visible' ) ) { // eslint-disable-line no-jquery/no-is
963 - const inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); // eslint-disable-line no-jquery/no-closest, formidable/no-jquery-variable-methods
964 - if ( inCollapsedSection.length ) {
965 - let frmTrigger = inCollapsedSection.prev();
966 - if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) { // eslint-disable-line formidable/no-jquery-variable-methods
967 - // If the frmTrigger object is the section description, check to see if the previous element is the trigger
968 - frmTrigger = frmTrigger.prev( '.frm_trigger' );
622 + if ( $fieldCont.length ) {
623 + if ( ! $fieldCont.is( ':visible' ) ) {
624 + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' );
625 + if ( inCollapsedSection.length ) {
626 + frmTrigger = inCollapsedSection.prev();
627 + if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) {
628 + // If the frmTrigger object is the section description, check to see if the previous element is the trigger
629 + frmTrigger = frmTrigger.prev( '.frm_trigger' );
630 + }
631 + frmTrigger.trigger( 'click' );
969 632 }
970 - frmTrigger.trigger( 'click' );
971 633 }
972 - }
973 634
974 - if ( $fieldCont.is( ':visible' ) ) { // eslint-disable-line no-jquery/no-is
975 - addFieldError( $fieldCont, key, response.errors );
976 - contSubmit = false;
635 + if ( $fieldCont.is( ':visible' ) ) {
636 + addFieldError( $fieldCont, key, response.errors );
637 + contSubmit = false;
638 + }
977 639 }
978 640 }
979 - }
980 641
981 - object.querySelectorAll( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).forEach( function( captchaEl ) {
982 - const recaptchaID = captchaEl.dataset.rid;
642 + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha' ).each( function() {
643 + var $recaptcha = jQuery( this ),
644 + recaptchaID = $recaptcha.data( 'rid' );
983 645
984 - if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
985 - if ( recaptchaID ) {
986 - grecaptcha.reset( recaptchaID );
987 - } else {
988 - grecaptcha.reset();
646 + if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
647 + if ( recaptchaID ) {
648 + grecaptcha.reset( recaptchaID );
649 + } else {
650 + grecaptcha.reset();
651 + }
989 652 }
990 - }
653 + });
991 654
992 - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) {
993 - hcaptcha.reset();
994 - }
995 - } );
655 + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
996 656
997 - if ( window.turnstile ) {
998 - object.querySelectorAll( '.frm-cf-turnstile' ).forEach(
999 - turnstileField => turnstileField.dataset.rid && turnstile.reset( turnstileField.dataset.rid )
1000 - );
1001 - }
657 + fieldset.removeClass( 'frm_doing_ajax' );
658 + scrollToFirstField( object );
1002 659
1003 - jQuery( document ).trigger( 'frmFormErrors', [ object, response ] );
660 + if ( contSubmit ) {
661 + object.submit();
662 + } else {
663 + jQuery( object ).prepend( response.error_message );
664 + checkForErrorsAndMaybeSetFocus();
665 + }
666 + } else {
667 + // there may have been a plugin conflict, or the form is not set to submit with ajax
1004 668
1005 - fieldsets.forEach( field => field.classList.remove( 'frm_doing_ajax' ) );
1006 - scrollToFirstField( object );
669 + showFileLoading( object );
1007 670
1008 - if ( contSubmit ) {
1009 671 object.submit();
1010 - } else {
1011 - object.insertAdjacentHTML( 'afterbegin', response.error_message );
1012 - checkForErrorsAndMaybeSetFocus();
1013 672 }
1014 - } else if ( ! willRedirect ) { // Avoid double submission if redirecting to a page.
1015 - // There may have been a plugin conflict, or the form is not set to submit with ajax.
1016 -
1017 - showFileLoading( object );
1018 -
673 + },
674 + error: function() {
675 + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
1019 676 object.submit();
1020 677 }
1021 - };
1022 -
1023 - const error = function() {
1024 - object.querySelectorAll( 'input[type="submit"], input[type="button"]' ).forEach(
1025 - button => button.disabled = false
1026 - );
1027 - object.submit();
1028 - };
1029 -
1030 - postToAjaxUrl( object, data, success, error );
678 + });
1031 679 }
1032 680
1033 - function postToAjaxUrl( form, data, success, error ) {
1034 - let ajaxUrl = frm_js.ajax_url;
1035 - const action = form.getAttribute( 'action' );
1036 -
1037 - if ( 'string' === typeof action && action.includes( '?action=frm_forms_preview' ) ) {
1038 - ajaxUrl = action.split( '?action=frm_forms_preview' )[ 0 ];
1039 - }
1040 -
1041 - const ajaxParams = {
1042 - type: 'POST',
1043 - url: ajaxUrl,
1044 - data,
1045 - success
1046 - };
1047 -
1048 - if ( 'function' === typeof error ) {
1049 - ajaxParams.error = error;
1050 - }
1051 -
1052 - jQuery.ajax( ajaxParams ); // eslint-disable-line no-jquery/no-ajax
1053 - }
1054 -
1055 681 function afterFormSubmitted( object, response ) {
1056 - const tempDiv = document.createElement( 'div' );
1057 - tempDiv.innerHTML = response.content;
1058 - const formCompleted = tempDiv.querySelector( '.frm_message' );
1059 - if ( formCompleted ) {
1060 - jQuery( document ).trigger( 'frmFormComplete', [ object, response ] );
682 + var formCompleted = jQuery( response.content ).find( '.frm_message' );
683 + if ( formCompleted.length ) {
684 + jQuery( document ).trigger( 'frmFormComplete', [ object, response ]);
1061 685 } else {
1062 - jQuery( document ).trigger( 'frmPageChanged', [ object, response ] );
686 + jQuery( document ).trigger( 'frmPageChanged', [ object, response ]);
1063 687 }
1064 688 }
1065 689
1066 - /**
1067 - * Trigger an event before the form is replaced with a success message.
1068 - *
1069 - * @since 6.9
1070 - *
1071 - * @param {HTMLElement} object The form.
1072 - * @param {Object} response The response from submitting the form with AJAX.
1073 - * @return {void}
1074 - */
1075 - function afterFormSubmittedBeforeReplace( object, response ) {
1076 - const tempDiv = document.createElement( 'div' );
1077 - tempDiv.innerHTML = response.content;
1078 - const formCompleted = tempDiv.querySelector( '.frm_message' );
1079 - if ( formCompleted ) {
1080 - triggerCustomEvent( document, 'frmFormCompleteBeforeReplace', { object, response } );
1081 - }
1082 - }
1083 -
1084 690 function removeAddedScripts( formContainer, formID ) {
1085 - const endReplace = document.querySelectorAll( `.frm_end_ajax_${ formID }` );
691 + var endReplace = jQuery( '.frm_end_ajax_' + formID );
1086 692 if ( endReplace.length ) {
1087 - formContainer.nextUntil( `.frm_end_ajax_${ formID }` ).remove();
1088 - endReplace.forEach( el => el.remove() );
693 + formContainer.nextUntil( '.frm_end_ajax_' + formID ).remove();
694 + endReplace.remove();
1089 695 }
1090 696 }
1091 697
1092 698 function maybeSlideOut( oldContent, newContent ) {
1093 - let c;
1094 - let newClass = 'frm_slideout';
1095 - if ( newContent.includes( ' frm_slide' ) ) {
699 + var c,
700 + newClass = 'frm_slideout';
701 + if ( newContent.indexOf( ' frm_slide' ) !== -1 ) {
1096 702 c = oldContent.children();
1097 - if ( newContent.includes( ' frm_going_back' ) ) {
703 + if ( newContent.indexOf( ' frm_going_back' ) !== -1 ) {
1098 704 newClass += ' frm_going_back';
1099 705 }
1100 706 c.removeClass( 'frm_going_back' );
1101 707 c.addClass( newClass );
@@ -1104,28 +710,30 @@
1104 710 return 0;
1105 711 }
1106 712
1107 713 function addUrlParam( response ) {
1108 - let url;
1109 - if ( history.pushState && response.page !== undefined ) {
714 + var url;
715 + if ( history.pushState && typeof response.page !== 'undefined' ) {
1110 716 url = addQueryVar( 'frm_page', response.page );
1111 - window.history.pushState( { html: response.html }, '', `?${ url }` );
717 + window.history.pushState({ 'html': response.html }, '', '?' + url );
1112 718 }
1113 719 }
1114 720
1115 721 function addQueryVar( key, value ) {
722 + var kvp, i, x;
723 +
1116 724 key = encodeURI( key );
1117 725 value = encodeURI( value );
1118 726
1119 - const kvp = document.location.search.substr( 1 ).split( '&' );
727 + kvp = document.location.search.substr( 1 ).split( '&' );
1120 728
1121 - let i = kvp.length;
729 + i = kvp.length;
1122 730 while ( i-- ) {
1123 - const x = kvp[ i ].split( '=' );
731 + x = kvp[i].split( '=' );
1124 732
1125 - if ( x[ 0 ] == key ) {
1126 - x[ 1 ] = value;
1127 - kvp[ i ] = x.join( '=' );
733 + if ( x[0] == key ) {
734 + x[1] = value;
735 + kvp[i] = x.join( '=' );
1128 736 break;
1129 737 }
1130 738 }
1131 739
@@ -1136,143 +744,66 @@
1136 744 return kvp.join( '&' );
1137 745 }
1138 746
1139 747 function addFieldError( $fieldCont, key, jsErrors ) {
1140 - const container = $fieldCont instanceof jQuery ? $fieldCont.get( 0 ) : $fieldCont;
748 + var input, id, describedBy;
749 + if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) {
750 + $fieldCont.addClass( 'frm_blank_field' );
751 + input = $fieldCont.find( 'input, select, textarea' );
752 + id = 'frm_error_field_' + key;
753 + describedBy = input.attr( 'aria-describedby' );
1141 754
1142 - if ( ! container || container.offsetParent === null ) {
1143 - return;
1144 - }
1145 -
1146 - container.classList.add( 'frm_blank_field' );
1147 - const input = container.querySelector( 'input, select, textarea' );
1148 - const id = getErrorElementId( key, input );
1149 -
1150 - let describedBy = input ? input.getAttribute( 'aria-describedby' ) : null;
1151 -
1152 - if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase
1153 - frmThemeOverride_frmPlaceError( key, jsErrors );
1154 - } else {
1155 - let errorHtml;
1156 - if ( jsErrors[ key ].includes( '<div' ) ) {
1157 - errorHtml = jsErrors[ key ];
755 + if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase
756 + frmThemeOverride_frmPlaceError( key, jsErrors );
1158 757 } else {
1159 - const roleString = frm_js.include_alert_role ? 'role="alert"' : '';
1160 - errorHtml = `<div class="frm_error" ${ roleString } id="${ id }">${ jsErrors[ key ] }</div>`;
1161 - }
1162 - container.insertAdjacentHTML( 'beforeend', errorHtml );
758 + if ( -1 !== jsErrors[key].indexOf( '<div' ) ) {
759 + $fieldCont.append(
760 + jsErrors[key]
761 + );
762 + } else {
763 + $fieldCont.append( '<div class="frm_error" id="' + id + '">' + jsErrors[key] + '</div>' );
764 + }
1163 765
1164 - if ( input ) {
1165 - if ( ! describedBy ) {
766 + if ( typeof describedBy === 'undefined' ) {
1166 767 describedBy = id;
1167 - } else if ( ! describedBy.includes( id ) && ! describedBy.includes( 'frm_error_field_' ) ) {
1168 - const { errorFirst } = input.dataset;
1169 - if ( errorFirst === '0' ) {
1170 - describedBy = `${ describedBy } ${ id }`;
1171 - } else {
1172 - describedBy = `${ id } ${ describedBy }`;
1173 - }
768 + } else if ( describedBy.indexOf( id ) === -1 ) {
769 + describedBy = describedBy + ' ' + id;
1174 770 }
1175 - input.setAttribute( 'aria-describedby', describedBy );
771 + input.attr( 'aria-describedby', describedBy );
1176 772 }
1177 - }
773 + input.attr( 'aria-invalid', true );
1178 774
1179 - if ( input ) {
1180 - if ( [ 'radio', 'checkbox' ].includes( input.type ) ) {
1181 - const group = input.closest( '[role="radiogroup"], [role="group"]' );
1182 - if ( group ) {
1183 - group.setAttribute( 'aria-invalid', 'true' );
1184 - }
1185 - } else {
1186 - input.setAttribute( 'aria-invalid', 'true' );
1187 - }
775 + jQuery( document ).trigger( 'frmAddFieldError', [ $fieldCont, key, jsErrors ]);
1188 776 }
1189 -
1190 - jQuery( document ).trigger( 'frmAddFieldError', [ jQuery( container ), key, jsErrors ] );
1191 777 }
1192 778
1193 - /**
1194 - * Get the ID to use for an error element added when submitting with AJAX.
1195 - *
1196 - * @param {string} key
1197 - * @param {HTMLElement} input
1198 - * @return {string} The ID to use for the error element.
1199 - */
1200 - function getErrorElementId( key, input ) {
1201 - if ( isNaN( key ) || ! input || ! input.id ) {
1202 - // If key isn't a number, assume it's already in the right format.
1203 - return `frm_error_field_${ key }`;
1204 - }
1205 - return `frm_error_${ input.id }`;
1206 - }
779 + function removeFieldError( $fieldCont ) {
780 + var errorMessage = $fieldCont.find( '.frm_error' ),
781 + errorId = errorMessage.attr( 'id' ),
782 + input = $fieldCont.find( 'input, select, textarea' ),
783 + describedBy = input.attr( 'aria-describedby' );
1207 784
1208 - /**
1209 - * Removes errors before validating with JS.
1210 - * This prevents issues with stale errors that has since been fixed.
1211 - *
1212 - * @param {HTMLElement|jQuery} fieldCont Field container element.
1213 - * @return {void}
1214 - */
1215 - function removeFieldError( fieldCont ) {
1216 - const container = fieldCont instanceof jQuery ? fieldCont.get( 0 ) : fieldCont;
1217 - if ( ! container ) {
1218 - return;
1219 - }
785 + $fieldCont.removeClass( 'frm_blank_field has-error' );
786 + errorMessage.remove();
787 + input.attr( 'aria-invalid', false );
1220 788
1221 - const errorMessage = container.querySelector( '.frm_error' );
1222 - const errorId = errorMessage ? errorMessage.id : '';
1223 - const input = container.querySelector( 'input, select, textarea' );
1224 - let describedBy = input ? input.getAttribute( 'aria-describedby' ) : null;
1225 -
1226 - container.classList.remove( 'frm_blank_field', 'has-error' );
1227 -
1228 - if ( input ) {
1229 - if ( 'true' === input.getAttribute( 'aria-invalid' ) ) {
1230 - input.setAttribute( 'aria-invalid', 'false' );
1231 - } else if ( [ 'radio', 'checkbox' ].includes( input.type ) ) {
1232 - const group = input.closest( '[role="radiogroup"], [role="group"]' );
1233 - if ( group ) {
1234 - group.setAttribute( 'aria-invalid', 'false' );
1235 - }
1236 - }
789 + if ( typeof describedBy !== 'undefined' ) {
790 + describedBy = describedBy.replace( errorId, '' );
791 + input.attr( 'aria-describedby', describedBy );
1237 792 }
1238 -
1239 - if ( errorMessage ) {
1240 - errorMessage.remove();
1241 - }
1242 -
1243 - if ( input ) {
1244 - input.removeAttribute( 'aria-describedby' );
1245 - if ( describedBy ) {
1246 - describedBy = describedBy.replace( errorId, '' ).trim();
1247 - if ( describedBy ) {
1248 - input.setAttribute( 'aria-describedby', describedBy );
1249 - }
1250 - }
1251 - }
1252 793 }
1253 794
1254 795 function removeAllErrors() {
1255 - document.querySelectorAll( '.form-field' ).forEach( field => {
1256 - field.classList.remove( 'frm_blank_field', 'has-error' );
1257 - } );
1258 - document.querySelectorAll( '.form-field .frm_error' ).forEach( error => error.remove() );
1259 - document.querySelectorAll( '.frm_error_style' ).forEach( error => error.remove() );
796 + jQuery( '.form-field' ).removeClass( 'frm_blank_field has-error' );
797 + jQuery( '.form-field .frm_error' ).replaceWith( '' );
798 + jQuery( '.frm_error_style' ).remove();
1260 799 }
1261 800
1262 - /**
1263 - * @param {HTMLElement|Object} object Form object.
1264 - * @return {void}
1265 - */
1266 801 function scrollToFirstField( object ) {
1267 - if ( 'function' === typeof object.get ) {
1268 - // Get the HTMLElement from a jQuery object.
1269 - object = object.get( 0 );
802 + var field = jQuery( object ).find( '.frm_blank_field' ).first();
803 + if ( field.length ) {
804 + frmFrontForm.scrollMsg( field, object, true );
1270 805 }
1271 - const field = object.querySelector( '.frm_blank_field' );
1272 - if ( field ) {
1273 - frmFrontForm.scrollMsg( jQuery( field ), object, true );
1274 - }
1275 806 }
1276 807
1277 808 function showSubmitLoading( $object ) {
1278 809 showLoadingIndicator( $object );
@@ -1280,9 +811,9 @@
1280 811 disableSaveDraft( $object );
1281 812 }
1282 813
1283 814 function showLoadingIndicator( $object ) {
1284 - if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) { // eslint-disable-line no-jquery/no-class, formidable/no-jquery-variable-methods
815 + if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) {
1285 816 addLoadingClass( $object );
1286 817 $object.trigger( 'frmStartFormLoading' );
1287 818 }
1288 819 }
@@ -1287,889 +818,316 @@
1287 818 }
1288 819 }
1289 820
1290 821 function addLoadingClass( $object ) {
1291 - const loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form';
822 + var loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form';
1292 823
1293 - $object.addClass( loadingClass ); // eslint-disable-line no-jquery/no-class, formidable/no-jquery-variable-methods
824 + $object.addClass( loadingClass );
1294 825 }
1295 826
1296 827 function isGoingToPrevPage( $object ) {
1297 - return typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object );
828 + return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) );
1298 829 }
1299 830
1300 - function removeSubmitLoading( _, enable, processesRunning ) {
831 + function removeSubmitLoading( $object, enable, processesRunning ) {
832 + var loadingForm;
833 +
1301 834 if ( processesRunning > 0 ) {
1302 835 return;
1303 836 }
1304 837
1305 - document.querySelectorAll( '.frm_loading_form' ).forEach( function( form ) {
1306 - form.classList.remove( 'frm_loading_form', 'frm_loading_prev' );
1307 - jQuery( form ).trigger( 'frmEndFormLoading' );
838 + loadingForm = jQuery( '.frm_loading_form' );
839 + loadingForm.removeClass( 'frm_loading_form' );
840 + loadingForm.removeClass( 'frm_loading_prev' );
1308 841
1309 - if ( enable === 'enable' ) {
1310 - enableSubmitButton( form );
1311 - enableSaveDraft( form );
1312 - }
1313 - } );
842 + loadingForm.trigger( 'frmEndFormLoading' );
843 +
844 + if ( enable === 'enable' ) {
845 + enableSubmitButton( loadingForm );
846 + enableSaveDraft( loadingForm );
847 + }
1314 848 }
1315 849
1316 850 function showFileLoading( object ) {
1317 - const loading = document.getElementById( 'frm_loading' );
1318 - if ( ! loading ) {
1319 - return;
851 + var fileval,
852 + loading = document.getElementById( 'frm_loading' );
853 + if ( loading !== null ) {
854 + fileval = jQuery( object ).find( 'input[type=file]' ).val();
855 + if ( typeof fileval !== 'undefined' && fileval !== '' ) {
856 + setTimeout( function() {
857 + jQuery( loading ).fadeIn( 'slow' );
858 + }, 2000 );
859 + }
1320 860 }
1321 -
1322 - const fileInput = object.querySelector( 'input[type=file]' );
1323 - const fileval = fileInput ? fileInput.value : '';
1324 - if ( fileval !== '' ) {
1325 - setTimeout( function() {
1326 - jQuery( loading ).fadeIn( 'slow' ); // eslint-disable-line no-jquery/no-fade
1327 - }, 2000 );
1328 - }
1329 861 }
1330 862
1331 - /**********************************************
1332 - * General Helpers
1333 - *********************************************/
1334 -
1335 - function confirmClick() {
863 + function clearDefault() {
1336 864 /*jshint validthis:true */
1337 - const message = this.dataset.frmconfirm;
1338 - return confirm( message );
865 + toggleDefault( jQuery( this ), 'clear' );
1339 866 }
1340 867
1341 - /**
1342 - * Check for -webkit-box-shadow css value for input:-webkit-autofill selector.
1343 - * If this is a match, the User is autofilling the input on a Webkit browser.
1344 - * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
1345 - */
1346 - function onHoneypotFieldChange() {
868 + function replaceDefault() {
1347 869 /*jshint validthis:true */
1348 - const css = window.getComputedStyle( this ).boxShadow;
1349 - if ( css?.match( /inset/ ) ) {
1350 - this.remove();
1351 - }
870 + toggleDefault( jQuery( this ), 'replace' );
1352 871 }
1353 872
1354 - /**
1355 - * Focus on the first sub field when clicking to the primary label of combo field.
1356 - *
1357 - * @since 4.10.02
1358 - */
1359 - function changeFocusWhenClickComboFieldLabel() {
1360 - let label;
873 + function toggleDefault( $thisField, e ) {
874 + // TODO: Fix this for a default value that is a number or array
875 + var thisVal,
876 + v = $thisField.data( 'frmval' ).replace( /(\n|\r\n)/g, '\r' );
877 + if ( v === '' || typeof v === 'undefined' ) {
878 + return false;
879 + }
880 + thisVal = $thisField.val().replace( /(\n|\r\n)/g, '\r' );
1361 881
1362 - const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1363 - comboInputsContainer.forEach( function( inputsContainer ) {
1364 - if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1365 - return;
882 + if ( 'replace' === e ) {
883 + if ( thisVal === '' ) {
884 + $thisField.addClass( 'frm_default' ).val( v );
1366 885 }
1367 -
1368 - label = inputsContainer.closest( '.frm_form_field' ).querySelector( '.frm_primary_label' );
1369 - if ( ! label ) {
1370 - return;
1371 - }
1372 -
1373 - label.addEventListener( 'click', function() {
1374 - inputsContainer.querySelector( '.frm_form_field:first-child input, .frm_form_field:first-child select, .frm_form_field:first-child textarea' ).focus();
1375 - } );
1376 - } );
1377 - }
1378 -
1379 - /**
1380 - * Sets focus on a the first subfield of a combo field that has an error.
1381 - *
1382 - * @since 6.16.3
1383 - *
1384 - * @param {HTMLElement} element
1385 - * @return {boolean} True if the focus was set on a combo field.
1386 - */
1387 - function maybeFocusOnComboSubField( element ) {
1388 - if ( 'FIELDSET' !== element.nodeName ) {
1389 - return false;
886 + } else if ( thisVal == v ) {
887 + $thisField.removeClass( 'frm_default' ).val( '' );
1390 888 }
1391 - if ( ! element.querySelector( '.frm_combo_inputs_container' ) ) {
1392 - return false;
1393 - }
1394 - const comboSubfield = element.querySelector( '[aria-invalid="true"]' );
1395 - if ( comboSubfield ) {
1396 - focusInput( comboSubfield );
1397 - return true;
1398 - }
1399 - return false;
1400 889 }
1401 890
1402 - function checkForErrorsAndMaybeSetFocus() {
1403 - if ( ! frm_js.focus_first_error ) {
1404 - return;
891 + function resendEmail() {
892 + /*jshint validthis:true */
893 + var $link = jQuery( this ),
894 + entryId = this.getAttribute( 'data-eid' ),
895 + formId = this.getAttribute( 'data-fid' ),
896 + label = $link.find( '.frm_link_label' );
897 + if ( label.length < 1 ) {
898 + label = $link;
1405 899 }
900 + label.append( '<span class="frm-wait"></span>' );
1406 901
1407 - const errors = document.querySelectorAll( '.frm_form_field .frm_error' );
1408 - if ( ! errors.length ) {
1409 - return;
1410 - }
1411 -
1412 - let element = errors[ 0 ];
1413 - let timeoutCallback;
1414 - do {
1415 - element = element.previousSibling;
1416 - if ( [ 'input', 'select', 'textarea' ].includes( element.nodeName.toLowerCase() ) ) {
1417 - focusInput( element );
1418 - break;
902 + jQuery.ajax({
903 + type: 'POST',
904 + url: frm_js.ajax_url,
905 + data: {
906 + action: 'frm_entries_send_email',
907 + entry_id: entryId,
908 + form_id: formId,
909 + nonce: frm_js.nonce
910 + },
911 + success: function( msg ) {
912 + var admin = document.getElementById( 'wpbody' );
913 + if ( admin === null ) {
914 + label.html( msg );
915 + } else {
916 + label.html( '' );
917 + $link.after( msg );
918 + }
1419 919 }
920 + });
921 + return false;
922 + }
1420 923
1421 - if ( maybeFocusOnComboSubField( element ) ) {
1422 - break;
1423 - }
924 + /**********************************************
925 + * General Helpers
926 + *********************************************/
1424 927
1425 - if ( element.classList !== undefined ) {
1426 - if ( element.classList.contains( 'html-active' ) ) {
1427 - timeoutCallback = function() {
1428 - const textarea = element.querySelector( 'textarea' );
1429 - if ( null !== textarea ) {
1430 - textarea.focus();
1431 - }
1432 - };
1433 - } else if ( element.classList.contains( 'tmce-active' ) ) {
1434 - timeoutCallback = function() {
1435 - tinyMCE.activeEditor.focus();
1436 - };
1437 - } else if ( element.classList.contains( 'frm_opt_container' ) ) {
1438 - const firstInput = element.querySelector( 'input' );
1439 - if ( firstInput ) {
1440 - focusInput( firstInput );
1441 - break;
1442 - }
1443 - }
1444 -
1445 - if ( 'function' === typeof timeoutCallback ) {
1446 - setTimeout( timeoutCallback, 0 );
1447 - break;
1448 - }
1449 - }
1450 - } while ( element.previousSibling );
928 + function confirmClick() {
929 + /*jshint validthis:true */
930 + var message = jQuery( this ).data( 'frmconfirm' );
931 + return confirm( message );
1451 932 }
1452 933
1453 - /**
1454 - * Focus a visible input, or possibly delay the focus event until the form has faded in.
1455 - *
1456 - * @since 6.16.3
1457 - *
1458 - * @param {HTMLElement} input
1459 - * @return {void}
1460 - */
1461 - function focusInput( input ) {
1462 - if ( input.offsetParent !== null ) {
1463 - input.focus();
934 + function toggleDiv() {
935 + /*jshint validthis:true */
936 + var div = jQuery( this ).data( 'frmtoggle' );
937 + if ( jQuery( div ).is( ':visible' ) ) {
938 + jQuery( div ).slideUp( 'fast' );
1464 939 } else {
1465 - triggerCustomEvent( document, 'frmMaybeDelayFocus', { input } );
940 + jQuery( div ).slideDown( 'fast' );
1466 941 }
942 + return false;
1467 943 }
1468 944
1469 - /**
1470 - * Does the same as jQuery( document ).on( 'event', 'selector', handler ).
1471 - *
1472 - * @since 5.4
1473 - *
1474 - * @param {string} event Event name.
1475 - * @param {string} selector Selector.
1476 - * @param {Function} handler Handler.
1477 - * @param {boolean | Object} options Options to be added to `addEventListener()` method. Default is `false`.
1478 - */
1479 - function documentOn( event, selector, handler, options ) {
1480 - if ( options === undefined ) {
1481 - options = false;
1482 - }
945 + /**********************************************
946 + * Fallback functions
947 + *********************************************/
1483 948
1484 - document.addEventListener( event, function( e ) {
1485 - let target;
949 + function addIndexOfFallbackForIE8() {
950 + var len, from;
1486 951
1487 - // loop parent nodes from the target to the delegation node.
1488 - for ( target = e.target; target && target != this; target = target.parentNode ) {
1489 - if ( target.matches && target.matches( selector ) ) {
1490 - handler.call( target, e );
1491 - break;
952 + if ( ! Array.prototype.indexOf ) {
953 + Array.prototype.indexOf = function( elt /*, from*/ ) {
954 + len = this.length >>> 0;
955 +
956 + from = Number( arguments[1]) || 0;
957 + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from );
958 + if ( from < 0 ) {
959 + from += len;
1492 960 }
1493 - }
1494 - }, options );
1495 - }
1496 961
1497 - function initFloatingLabels() {
1498 - const selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea';
1499 - const floatClass = 'frm_label_float_top';
1500 -
1501 - const checkFloatLabel = function( input ) {
1502 - const container = input.closest( '.frm_inside_container' );
1503 - if ( ! container ) {
1504 - return;
1505 - }
1506 -
1507 - const shouldFloatTop = input.value || document.activeElement === input;
1508 -
1509 - container.classList.toggle( floatClass, shouldFloatTop );
1510 -
1511 - if ( 'SELECT' === input.tagName ) {
1512 - const firstOpt = input.querySelector( 'option:first-child' );
1513 -
1514 - if ( shouldFloatTop ) {
1515 - if ( firstOpt.hasAttribute( 'data-label' ) ) {
1516 - firstOpt.textContent = firstOpt.getAttribute( 'data-label' );
1517 - firstOpt.removeAttribute( 'data-label' );
962 + for ( ; from < len; from++ ) {
963 + if ( from in this && this[from] === elt ) {
964 + return from;
1518 965 }
1519 - } else if ( firstOpt.textContent ) {
1520 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1521 - firstOpt.textContent = '';
1522 966 }
1523 - }
1524 - };
1525 -
1526 - const checkDropdownLabel = function() {
1527 - document.querySelectorAll( `.frm-show-form .frm_inside_container:not(.${ floatClass }) select` ).forEach( function( input ) {
1528 - const firstOpt = input.querySelector( 'option:first-child' );
1529 -
1530 - if ( firstOpt.textContent ) {
1531 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1532 - firstOpt.textContent = '';
1533 - }
1534 - } );
1535 - };
1536 -
1537 - [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
1538 - documentOn(
1539 - eventName,
1540 - selector,
1541 - function( event ) {
1542 - checkFloatLabel( event.target );
1543 - },
1544 - true
1545 - );
1546 - } );
1547 -
1548 - const runOnLoad = function( firstLoad ) {
1549 - if ( firstLoad && document.activeElement && [ 'INPUT', 'SELECT', 'TEXTAREA' ].includes( document.activeElement.tagName ) ) {
1550 - checkFloatLabel( document.activeElement );
1551 - } else if ( firstLoad ) {
1552 - document.querySelectorAll( '.frm_inside_container' ).forEach(
1553 - function( container ) {
1554 - const input = container.querySelector( 'input, select, textarea' );
1555 - if ( input && '' !== input.value ) {
1556 - checkFloatLabel( input );
1557 - }
1558 - }
1559 - );
1560 - }
1561 -
1562 - checkDropdownLabel();
1563 - calcProductsTotal();
1564 - };
1565 -
1566 - runOnLoad( true );
1567 -
1568 - jQuery( document ).on( 'frmPageChanged', function( event ) {
1569 - runOnLoad();
1570 - } );
1571 -
1572 - document.addEventListener( 'frm_after_start_over', function( event ) {
1573 - runOnLoad();
1574 - } );
1575 - }
1576 -
1577 - function shouldUpdateValidityMessage( target ) {
1578 - if ( 'INPUT' !== target.nodeName ) {
1579 - return false;
967 + return -1;
968 + };
1580 969 }
1581 -
1582 - if ( ! target.dataset.invmsg ) {
1583 - return false;
1584 - }
1585 -
1586 - if ( 'text' !== target.getAttribute( 'type' ) ) {
1587 - return false;
1588 - }
1589 -
1590 - if ( target.classList.contains( 'frm_verify' ) ) {
1591 - return false;
1592 - }
1593 -
1594 - return true;
1595 970 }
1596 971
1597 - function maybeClearCustomValidityMessage( event, field ) {
1598 - let key;
1599 - let isInvalid = false;
1600 -
1601 - if ( ! shouldUpdateValidityMessage( field ) ) {
1602 - return;
972 + function addTrimFallbackForIE8() {
973 + if ( typeof String.prototype.trim !== 'function' ) {
974 + String.prototype.trim = function() {
975 + return this.replace( /^\s+|\s+$/g, '' );
976 + };
1603 977 }
1604 -
1605 - for ( key in field.validity ) {
1606 - if ( 'customError' === key ) {
1607 - continue;
1608 - }
1609 - if ( 'valid' !== key && field.validity[ key ] === true ) {
1610 - isInvalid = true;
1611 - break;
1612 - }
1613 - }
1614 -
1615 - if ( ! isInvalid ) {
1616 - field.setCustomValidity( '' );
1617 - }
1618 978 }
1619 979
1620 - function maybeShowNewTabFallbackMessage() {
1621 - if ( ! window.frmShowNewTabFallback ) {
1622 - return;
1623 - }
980 + function addFilterFallbackForIE8() {
981 + var t, len, res, thisp, i, val;
1624 982
1625 - const messageEl = document.querySelector( `#frm_form_${ frmShowNewTabFallback.formId }_container .frm_message` );
1626 - if ( ! messageEl ) {
1627 - return;
1628 - }
983 + if ( ! Array.prototype.filter ) {
1629 984
1630 - messageEl.insertAdjacentHTML( 'beforeend', ` ${ frmShowNewTabFallback.message }` );
1631 - }
985 + Array.prototype.filter = function( fun /*, thisp */ ) {
1632 986
1633 - function setCustomValidityMessage() {
1634 - const forms = document.getElementsByClassName( 'frm-show-form' );
1635 - const { length } = forms;
987 + if ( this === void 0 || this === null ) {
988 + throw new TypeError();
989 + }
1636 990
1637 - for ( let index = 0; index < length; ++index ) {
1638 - forms[ index ].addEventListener(
1639 - 'invalid',
1640 - function( event ) {
1641 - const { target } = event;
991 + t = Object( this );
992 + len = t.length >>> 0;
993 + if ( typeof fun !== 'function' ) {
994 + throw new TypeError();
995 + }
1642 996
1643 - if ( shouldUpdateValidityMessage( target ) ) {
1644 - target.setCustomValidity( target.dataset.invmsg );
997 + res = [];
998 + thisp = arguments[1];
999 + for ( i = 0; i < len; i++ ) {
1000 + if ( i in t ) {
1001 + val = t[i]; // in case fun mutates this
1002 + if ( fun.call( thisp, val, i, t ) ) {
1003 + res.push( val );
1004 + }
1645 1005 }
1646 - },
1647 - true
1648 - );
1649 - }
1650 - }
1006 + }
1651 1007
1652 - function enableSubmitButtonOnBackButtonPress() {
1653 - window.addEventListener( 'pageshow', function( event ) {
1654 - if ( event.persisted ) {
1655 - document.querySelectorAll( '.frm_loading_form' ).forEach(
1656 - function( form ) {
1657 - enableSubmitButton( form );
1658 - }
1659 - );
1660 - removeSubmitLoading();
1661 - }
1662 - } );
1663 - }
1664 -
1665 - /**
1666 - * Destroys the formidable generated global hcaptcha object since it wouldn't otherwise render.
1667 - */
1668 - function destroyhCaptcha() {
1669 - if ( ! window.hasOwnProperty( 'hcaptcha' ) || ! document.querySelector( '.frm-show-form .h-captcha' ) ) {
1670 - return;
1008 + return res;
1009 + };
1671 1010 }
1672 - window.hcaptcha = null;
1673 1011 }
1674 1012
1675 - /**
1676 - * @since 6.16.3
1677 - *
1678 - * @return {string} Unique key, used for duplicate checks.
1679 - */
1680 - function getUniqueKey() {
1681 - const uniqueKey = Array.from( window.crypto.getRandomValues( new Uint8Array( 8 ) ) )
1682 - .map( b => b.toString( 16 ).padStart( 2, '0' ) )
1683 - .join( '' );
1684 - const timestamp = Date.now().toString( 16 );
1685 - return `${ uniqueKey }-${ timestamp }`;
1686 - }
1013 + function addKeysFallbackForIE8() {
1014 + var keys, i;
1687 1015
1688 - /**
1689 - * Animates the scroll position of the document.
1690 - *
1691 - * @since 6.20
1692 - *
1693 - * @param {number} start
1694 - * @param {number} end
1695 - * @param {number} duration
1696 - * @return {void}
1697 - */
1698 - function animateScroll( start, end, duration ) {
1699 - if ( ! window.hasOwnProperty( 'performance' ) || ! window.hasOwnProperty( 'requestAnimationFrame' ) ) {
1700 - document.documentElement.scrollTop = end;
1701 - return;
1702 - }
1016 + if ( ! Object.keys ) {
1017 + Object.keys = function( obj ) {
1018 + keys = [];
1703 1019
1704 - const startTime = performance.now();
1705 - const step = currentTime => {
1706 - const progress = Math.min( ( currentTime - startTime ) / duration, 1 );
1707 - document.documentElement.scrollTop = start + ( ( end - start ) * progress );
1708 - if ( progress < 1 ) {
1709 - requestAnimationFrame( step );
1710 - }
1711 - };
1712 - requestAnimationFrame( step );
1713 - }
1020 + for ( i in obj ) {
1021 + if ( obj.hasOwnProperty( i ) ) {
1022 + keys.push( i );
1023 + }
1024 + }
1714 1025
1715 - /**
1716 - * Make sure that the captcha label for a reCAPTCHA or Turnstile field matches the response input ID.
1717 - * This is determined dynamically, so we check for the ID after the input is rendered.
1718 - * hCaptcha is handled separately, in the frmCaptcha function as it is not rendered explicitly.
1719 - *
1720 - * @since 6.25.1
1721 - *
1722 - * @param {HTMLElement} captcha
1723 - * @return {void}
1724 - */
1725 - function maybeFixCaptchaLabel( captcha ) {
1726 - const form = captcha.closest( 'form' );
1727 - if ( ! form ) {
1728 - return;
1026 + return keys;
1027 + };
1729 1028 }
1730 -
1731 - const label = form.querySelector( 'label[for="g-recaptcha-response"], label[for="cf-turnstile-response"]' );
1732 - const captchaResponse = form.querySelector( '[name="g-recaptcha-response"], [name="cf-turnstile-response"]' );
1733 -
1734 - if ( label && captchaResponse ) {
1735 - label.htmlFor = captchaResponse.id;
1736 - }
1737 1029 }
1738 1030
1739 1031 /**
1740 - * Check to make sure the quantity field value is within the min and max values.
1741 - *
1742 - * @param {HTMLElement} input
1743 - * @return {number} The quantity value.
1032 + * Check for -webkit-box-shadow css value for input:-webkit-autofill selector.
1033 + * If this is a match, the User is autofilling the input on a Webkit browser.
1034 + * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
1744 1035 */
1745 - function checkQuantityFieldMinMax( input ) {
1746 - if ( '' === input.value ) {
1747 - // Leave the value if it is empty.
1748 - return 0;
1036 + function onHoneypotFieldChange() {
1037 + var css = jQuery( this ).css( 'box-shadow' );
1038 + if ( css.match( /inset/ ) ) {
1039 + this.parentNode.removeChild( this );
1749 1040 }
1750 -
1751 - const val = parseFloat( input.value ? input.value.trim() : 0 );
1752 - if ( isNaN( val ) ) {
1753 - return 0;
1754 - }
1755 -
1756 - let max = input.hasAttribute( 'max' ) ? parseFloat( input.getAttribute( 'max' ) ) : 0;
1757 - let min = input.hasAttribute( 'min' ) ? parseFloat( input.getAttribute( 'min' ) ) : 0;
1758 -
1759 - max = isNaN( max ) ? 0 : max;
1760 - min = isNaN( min ) ? 0 : Math.max( 0, min );
1761 -
1762 - if ( val < min ) {
1763 - input.value = min;
1764 - return min;
1765 - }
1766 -
1767 - if ( 0 !== max && val > max ) {
1768 - input.value = max;
1769 - return max;
1770 - }
1771 -
1772 - return val;
1773 1041 }
1774 1042
1775 - function triggerChange( input, fieldKey ) {
1776 - if ( fieldKey === undefined ) {
1777 - fieldKey = 'dependent';
1778 - }
1779 -
1780 - jQuery( input ).trigger( { type: 'change', selfTriggered: true, frmTriggered: fieldKey } );
1781 - }
1782 -
1783 1043 /**
1784 - * Calculates the total price.
1044 + * Focus on the first sub field when clicking to the primary label of combo field.
1785 1045 *
1786 - * @param {Event|undefined} e The event object.
1787 - * @return {void}
1046 + * @since 4.10.02
1788 1047 */
1789 - function calcProductsTotal( e ) {
1790 - if ( 'object' === typeof frmProForm ) {
1791 - // Pro is installed, use the Pro JS.
1792 - return;
1793 - }
1048 + function changeFocusWhenClickComboFieldLabel() {
1049 + let label;
1794 1050
1795 - if ( typeof __FRMCURR === 'undefined' ) {
1796 - return;
1797 - }
1798 -
1799 - const totalFields = document.querySelectorAll( '[data-frmtotal]' );
1800 - if ( ! totalFields.length ) {
1801 - return;
1802 - }
1803 -
1804 - const formTotals = [];
1805 -
1806 - totalFields.forEach( totalField => {
1807 - let total = 0;
1808 - const form = totalField.closest( 'form' );
1809 -
1810 - if ( ! form ) {
1051 + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1052 + comboInputsContainer.forEach( function( inputsContainer ) {
1053 + if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1811 1054 return;
1812 1055 }
1813 1056
1814 - const formId = form.querySelector( 'input[name="form_id"]' ).value;
1815 - const currency = getCurrency( formId );
1816 -
1817 - if ( undefined !== formTotals[ formId ] ) {
1818 - total = formTotals[ formId ];
1819 - } else {
1820 - form.querySelectorAll( 'input[data-frmprice],select:has([data-frmprice])' ).forEach( function( input ) {
1821 - let quantity = 0;
1822 - let price = 0;
1823 - const isSingle = 'hidden' === input.type;
1824 -
1825 - if ( input.tagName === 'SELECT' ) {
1826 - if ( input.selectedIndex !== -1 ) {
1827 - price = input.options[ input.selectedIndex ].getAttribute( 'data-frmprice' );
1828 - }
1829 - } else {
1830 - if ( ! isSingle && ! input.matches( ':checked' ) ) {
1831 - return;
1832 - }
1833 - price = input.getAttribute( 'data-frmprice' );
1834 - }
1835 -
1836 - if ( ! price ) {
1837 - price = 0;
1838 - } else {
1839 - price = preparePrice( price, currency );
1840 - quantity = getQuantity( input );
1841 - price = parseFloat( quantity ) * parseFloat( price );
1842 - }
1843 -
1844 - if ( 'true' === input.getAttribute( 'data-frmdiscount' ) ) {
1845 - price = price * -1;
1846 - }
1847 -
1848 - total += price;
1849 - } );
1850 -
1851 - formTotals[ formId ] = total;
1852 - }
1853 -
1854 - total = isNaN( total ) ? 0 : total;
1855 -
1856 - // Set a decimal separator for currency if no default for it
1857 - currency.decimal_separator = currency.decimal_separator.trim(); // first remove unnecessary space(s)
1858 - if ( ! currency.decimal_separator.length ) {
1859 - currency.decimal_separator = '.';
1860 - }
1861 -
1862 - totalField.value = roundTotal( total, currency );
1863 - total = normalizeTotal( total, currency );
1864 -
1865 - // because of e.g. fields that might be using this field for calculations
1866 - triggerChange( totalField );
1867 -
1868 - total = formatCurrency( total, currency );
1869 - const formatted = totalField.previousElementSibling;
1870 - if ( formatted?.matches( '.frm_total_formatted' ) ) {
1871 - // Use innerHTML so that currency symbols like Euros can render and not their encoded string value.
1872 - formatted.innerHTML = total;
1057 + label = inputsContainer.closest( '.frm_form_field' ).querySelector( '.frm_primary_label' );
1058 + if ( ! label ) {
1873 1059 return;
1874 1060 }
1875 1061
1876 - const formattedEls = totalField.closest( '.frm_form_field' ).querySelectorAll( '.frm_total_formatted' );
1877 - formattedEls.forEach( formattedEl => {
1878 - // Use innerHTML so that currency symbols like Euros can render and not their encoded string value.
1879 - formattedEl.innerHTML = total;
1880 - } );
1881 - } );
1062 + label.addEventListener( 'click', function( e ) {
1063 + inputsContainer.querySelector( '.frm_form_field:first-child input, .frm_form_field:first-child select, .frm_form_field:first-child textarea' ).focus();
1064 + });
1065 + });
1882 1066 }
1883 1067
1884 - /**
1885 - * Round total and maybe add trailing zeros so formatCurrency has a proper format to work with.
1886 - *
1887 - * @param {number} total The total amount to normalize.
1888 - * @param {Object} currency The currency object containing decimal information.
1889 - * @return {string} The normalized total amount.
1890 - */
1891 - function normalizeTotal( total, currency ) {
1892 - const isLargeTotal = total > Number.MAX_SAFE_INTEGER;
1068 + function checkForErrorsAndMaybeSetFocus() {
1069 + var errors, element, timeoutCallback;
1893 1070
1894 - total = roundTotal( total, currency );
1895 -
1896 - return maybeAddTrailingZeroToPrice( total, currency, isLargeTotal );
1897 - }
1898 -
1899 - function roundTotal( total, currency ) {
1900 - const isLargeTotal = total > Number.MAX_SAFE_INTEGER;
1901 -
1902 - if ( ! isLargeTotal ) {
1903 - const { decimals } = currency;
1904 - total = decimals > 0 ? round10( total, decimals ) : Math.ceil( total );
1071 + errors = document.querySelectorAll( '.frm_form_field .frm_error' );
1072 + if ( ! errors.length ) {
1073 + return;
1905 1074 }
1906 1075
1907 - return total;
1908 - }
1909 -
1910 - function round10( value, decimals ) {
1911 - return Number( `${ Math.round( `${ value }e${ decimals }` ) }e-${ decimals }` );
1912 - }
1913 -
1914 - /**
1915 - * Format a numeric value according to the specified currency format settings.
1916 - *
1917 - * @param {string} total The numeric value to format.
1918 - * @param {Object} currency The currency formatting configuration.
1919 - * @return {string} The formatted currency string.
1920 - */
1921 - function formatCurrency( total, currency ) {
1922 - total = maybeAddTrailingZeroToPrice( total, currency );
1923 - if ( total.length && ( total[ total.length - 1 ] === '.' || total[ total.length - 1 ] === currency.decimal_separator ) ) {
1924 - total = total.substr( 0, total.length - 1 );
1925 - }
1926 -
1927 - total = maybeRemoveTrailingZerosFromPrice( total, currency );
1928 - total = addThousands( total, currency );
1929 -
1930 - const leftSymbol = currency.symbol_left ? ( currency.symbol_left + currency.symbol_padding ) : '';
1931 - const rightSymbol = currency.symbol_right ? ( currency.symbol_padding + currency.symbol_right ) : '';
1932 -
1933 - return `${ leftSymbol }${ total }${ rightSymbol }`;
1934 - }
1935 -
1936 - /**
1937 - * Gets currency from form id.
1938 - *
1939 - * @param {number} formId Form ID.
1940 - * @return {Object} Currency object.
1941 - */
1942 - function getCurrency( formId ) {
1943 - if ( undefined !== window.__FRMCURR && undefined !== window.__FRMCURR[ formId ] ) {
1944 - return window.__FRMCURR[ formId ];
1945 - }
1946 -
1947 - return {
1948 - symbol_left: '$',
1949 - symbol_right: '',
1950 - symbol_padding: '',
1951 - thousand_separator: ',',
1952 - decimal_separator: '.',
1953 - decimals: 2,
1954 - };
1955 - }
1956 -
1957 - /**
1958 - * Gets quantity.
1959 - *
1960 - * @param {HTMLElement} field The field element.
1961 - * @return {number} The quantity.
1962 - */
1963 - function getQuantity( field ) {
1964 - const fieldID = frmFrontForm.getFieldId( field, false );
1965 - if ( ! fieldID ) {
1966 - return 0;
1967 - }
1968 -
1969 - const quantityField = getQuantityField( field, fieldID );
1970 - if ( ! quantityField ) {
1971 - // If there is no quantity field, assume 1.
1972 - return 1;
1973 - }
1974 -
1975 - return checkQuantityFieldMinMax( quantityField );
1976 - }
1977 -
1978 - /**
1979 - * Gets quantity field.
1980 - *
1981 - * @param {HTMLElement} element The element.
1982 - * @param {number} fieldID The field ID.
1983 - * @return {HTMLElement|null} The quantity field.
1984 - */
1985 - function getQuantityField( element, fieldID ) {
1986 - const quantityFields = element.closest( 'form' ).querySelectorAll( '[data-frmproduct]' );
1987 - if ( ! quantityFields.length ) {
1988 - return null;
1989 - }
1990 -
1991 - fieldID = fieldID.toString();
1992 -
1993 - return Array.from( quantityFields ).find( element => {
1994 - let ids;
1995 -
1996 - ids = JSON.parse( element.getAttribute( 'data-frmproduct' ).trim() );
1997 - if ( '' === ids ) {
1998 - return false;
1076 + element = errors[0];
1077 + do {
1078 + element = element.previousSibling;
1079 + if ( -1 !== [ 'input', 'select', 'textarea' ].indexOf( element.nodeName.toLowerCase() ) ) {
1080 + element.focus();
1081 + break;
1999 1082 }
2000 1083
2001 - // Convert to array if necessary because of existing fields that are already using single product fields.
2002 - ids = 'string' === typeof ids ? [ ids ] : ids;
2003 - return ids.includes( fieldID );
2004 - } );
2005 - }
2006 -
2007 - /**
2008 - * Prepare a price for calculation.
2009 - *
2010 - * @param {number|string} price The price to prepare.
2011 - * @param {Object} currency The currency object containing decimal information.
2012 - * @return {string} The prepared price.
2013 - */
2014 - function preparePrice( price, currency ) {
2015 - if ( ! price ) {
2016 - return 0;
2017 - }
2018 - price = `${ price }`; // convert to string just to be sure
2019 -
2020 - const regex = getRegexForPrice( currency );
2021 -
2022 - const matches = price.match( regex );
2023 - if ( null === matches ) {
2024 - return 0;
2025 - }
2026 -
2027 - price = matches.length ? matches[ matches.length - 1 ] : 0;
2028 - price = price.trim();
2029 -
2030 - // Fix issues with parsing Fr.15.00. The regex catches .15.00.
2031 - // This checks for the leading decimal and removes it.
2032 - if ( currency.decimal_separator === '.' && 3 === price.split( '.' ).length && price[ 0 ] === '.' ) {
2033 - price = price.substr( 1 );
2034 - }
2035 -
2036 - if ( price ) {
2037 - price = maybeUseDecimal( price, currency );
2038 - price = price.split( currency.thousand_separator ).join( '' ).replace( currency.decimal_separator, '.' );
2039 - }
2040 -
2041 - return price;
2042 - }
2043 -
2044 - /**
2045 - * @param {Object} currency The currency object.
2046 - * @return {RegExp} The regular expression object.
2047 - */
2048 - function getRegexForPrice( currency ) {
2049 - let regexString = '[0-9,.';
2050 -
2051 - if ( currency.thousand_separator !== '.' && currency.thousand_separator !== ',' ) {
2052 - regexString += currency.thousand_separator;
2053 - }
2054 - if ( currency.decimal_separator !== '.' && currency.decimal_separator !== ',' ) {
2055 - regexString += currency.decimal_separator;
2056 - }
2057 -
2058 - regexString += ']*\\.?\\,?[0-9]+';
2059 -
2060 - return new RegExp( regexString, 'g' );
2061 - }
2062 -
2063 - /**
2064 - * Maybe replace the decimal separator with the currency's decimal separator.
2065 - *
2066 - * @param {string} price The price string.
2067 - * @param {Object} currency The currency object.
2068 - * @return {string} The modified price string.
2069 - */
2070 - function maybeUseDecimal( price, currency ) {
2071 - let usedForDecimal;
2072 - let priceParts;
2073 - if ( '.' === currency.thousand_separator ) {
2074 - priceParts = price.split( '.' );
2075 - usedForDecimal = 2 === priceParts.length && 2 === priceParts[ 1 ].length;
2076 - if ( usedForDecimal ) {
2077 - price = price.replace( '.', currency.decimal_separator );
2078 - }
2079 - }
2080 - return price;
2081 - }
2082 -
2083 - /**
2084 - * Add trailing zeros to a price if necessary and replace the decimal separator.
2085 - *
2086 - * @param {number|string} price The price to format.
2087 - * @param {Object} currency The currency object containing the decimal separator.
2088 - * @param {boolean} [force=false] Whether to force processing even if the price is not a number.
2089 - * @return {string} The formatted price string.
2090 - */
2091 - function maybeAddTrailingZeroToPrice( price, currency, force = false ) {
2092 - if ( 'number' !== typeof price && ! force ) {
2093 - return price;
2094 - }
2095 -
2096 - price = String( price ); // first convert to string
2097 - const pos = price.indexOf( '.' );
2098 -
2099 - if ( pos === -1 ) {
2100 - price = `${ price }.`;
2101 -
2102 - for ( let n = 0; n < currency.decimals; ++n ) {
2103 - price += '0';
2104 - }
2105 - } else {
2106 - const decimalsString = price.substring( pos + 1 );
2107 - if ( decimalsString.length < currency.decimals ) {
2108 - if ( decimalsString.length < 2 ) {
2109 - price += '0';
1084 + if ( 'undefined' !== typeof element.classList ) {
1085 + if ( element.classList.contains( 'html-active' ) ) {
1086 + timeoutCallback = function() {
1087 + var textarea = element.querySelector( 'textarea' );
1088 + if ( null !== textarea ) {
1089 + textarea.focus();
1090 + }
1091 + };
1092 + } else if ( element.classList.contains( 'tmce-active' ) ) {
1093 + timeoutCallback = function() {
1094 + tinyMCE.activeEditor.focus();
1095 + };
2110 1096 }
2111 1097
2112 - for ( let n = 2; n < currency.decimals; ++n ) {
2113 - price += '0';
1098 + if ( 'function' === typeof timeoutCallback ) {
1099 + setTimeout( timeoutCallback, 0 );
1100 + break;
2114 1101 }
2115 1102 }
2116 - }
2117 -
2118 - return price.replace( '.', currency.decimal_separator );
1103 + } while ( element.previousSibling );
2119 1104 }
2120 1105
2121 - /**
2122 - * Format a numeric string by adding thousand separators.
2123 - *
2124 - * @param {string|number} price The numeric value to format.
2125 - * @param {Object} options Formatting options.
2126 - * @param {string} options.decimal_separator Character used as decimal separator.
2127 - * @param {string} options.thousand_separator Character used as thousand separator.
2128 - *
2129 - * @return {string} The price string with thousand separators.
2130 - */
2131 - function addThousands( price, options ) {
2132 - const split = options.decimal_separator === ''
2133 - ? [ price.toString() ]
2134 - : price.split( options.decimal_separator );
1106 + return {
1107 + init: function() {
1108 + jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
1109 + jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
2135 1110
2136 - if ( options.thousand_separator ) {
2137 - split[ 0 ] = split[ 0 ].replace( /\B(?=(\d{3})+(?!\d))/g, options.thousand_separator );
2138 - }
1111 + jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
1112 + if ( jQuery( this ).val() === '' ) {
1113 + jQuery( this ).trigger( 'blur' );
1114 + }
1115 + });
2139 1116
2140 - return split.join( options.decimal_separator );
2141 - }
1117 + jQuery( document ).on( 'focus', '.frm_toggle_default', clearDefault );
1118 + jQuery( document ).on( 'blur', '.frm_toggle_default', replaceDefault );
1119 + jQuery( '.frm_toggle_default' ).trigger( 'blur' );
2142 1120
2143 - /**
2144 - * Maybe remove trailing zeros from a price string.
2145 - *
2146 - * @param {string} price The price string.
2147 - * @param {Object} currency The currency data.
2148 - *
2149 - * @return {string} The price string with trailing zeros removed.
2150 - */
2151 - function maybeRemoveTrailingZerosFromPrice( price, currency ) {
2152 - const split = price.split( currency.decimal_separator );
2153 - if ( 2 !== split.length || split[ 1 ].length <= currency.decimals ) {
2154 - return price;
2155 - }
2156 - if ( 0 === currency.decimals ) {
2157 - return split[ 0 ];
2158 - }
2159 - return `${ split[ 0 ] }${ currency.decimal_separator }${ split[ 1 ].substr( 0, currency.decimals ) }`;
2160 - }
1121 + jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail );
2161 1122
2162 - return {
2163 - init() {
2164 - jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
2165 - jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
2166 -
2167 1123 jQuery( document ).on( 'change', '.frm-show-form input[name^="item_meta"], .frm-show-form select[name^="item_meta"], .frm-show-form textarea[name^="item_meta"]', frmFrontForm.fieldValueChanged );
1124 + jQuery( document ).on( 'change keyup', '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea', maybeShowLabel );
2168 1125
2169 - jQuery( document ).on( 'change', '.frm_verify[id^=field_]', onHoneypotFieldChange );
1126 + jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange );
2170 1127
2171 1128 jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick );
1129 + jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv );
2172 1130
2173 1131 checkForErrorsAndMaybeSetFocus();
2174 1132
2175 1133 // Focus on the first sub field when clicking to the primary label of combo field.
@@ -2174,128 +1132,102 @@
2174 1132
2175 1133 // Focus on the first sub field when clicking to the primary label of combo field.
2176 1134 changeFocusWhenClickComboFieldLabel();
2177 1135
2178 - initFloatingLabels();
2179 - maybeShowNewTabFallbackMessage();
1136 + // Add fallbacks for the beloved IE8
1137 + addIndexOfFallbackForIE8();
1138 + addTrimFallbackForIE8();
1139 + addFilterFallbackForIE8();
1140 + addKeysFallbackForIE8();
1141 + },
2180 1142
2181 - jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage );
2182 - setCustomValidityMessage();
2183 - jQuery( document ).on( 'frmFieldChanged', maybeClearCustomValidityMessage );
2184 -
2185 - setSelectPlaceholderColor();
2186 -
2187 - // Elementor popup show event. Fix Elementor Popup && FF Captcha field conflicts
2188 - jQuery( document ).on( 'elementor/popup/show', frmRecaptcha );
2189 -
2190 - enableSubmitButtonOnBackButtonPress();
2191 - jQuery( document ).on(
2192 - 'frmPageChanged',
2193 - destroyhCaptcha
2194 - );
2195 -
2196 - jQuery( document ).on( 'frmAfterAddRow frmAfterRemoveRow', calcProductsTotal );
2197 - jQuery( document ).on( 'change', '[type="checkbox"][data-frmprice],[type="radio"][data-frmprice],[type="hidden"][data-frmprice],select:has([data-frmprice])', calcProductsTotal );
2198 - jQuery( document ).on( 'keyup change', '[data-frmproduct],[type="text"][data-frmprice]', calcProductsTotal );
2199 - calcProductsTotal();
1143 + getFieldId: function( field, fullID ) {
1144 + return getFieldId( field, fullID );
2200 1145 },
2201 1146
2202 - getFieldId,
1147 + renderRecaptcha: function( captcha ) {
1148 + var formID, recaptchaID,
1149 + size = captcha.getAttribute( 'data-size' ),
1150 + rendered = captcha.getAttribute( 'data-rid' ) !== null,
1151 + params = {
1152 + 'sitekey': captcha.getAttribute( 'data-sitekey' ),
1153 + 'size': size,
1154 + 'theme': captcha.getAttribute( 'data-theme' )
1155 + };
2203 1156
2204 - /**
2205 - * Render a captcha field.
2206 - *
2207 - * @param {HTMLElement} captcha
2208 - * @param {string} captchaSelector
2209 - * @return {void}
2210 - */
2211 - renderCaptcha( captcha, captchaSelector ) {
2212 - const rendered = captcha.getAttribute( 'data-rid' ) !== null;
2213 1157 if ( rendered ) {
2214 1158 return;
2215 1159 }
2216 1160
2217 - const size = captcha.getAttribute( 'data-size' );
2218 - const params = {
2219 - sitekey: captcha.getAttribute( 'data-sitekey' ),
2220 - size,
2221 - theme: captcha.getAttribute( 'data-theme' )
2222 - };
2223 -
2224 1161 if ( size === 'invisible' ) {
2225 - const formID = captcha.closest( 'form' )?.querySelector( 'input[name="form_id"]' )?.value;
2226 -
2227 - const captchaLabel = captcha.closest( '.frm_form_field' )?.querySelector( '.frm_primary_label' );
2228 - if ( captchaLabel ) {
2229 - captchaLabel.style.display = 'none';
2230 - }
2231 -
1162 + formID = jQuery( captcha ).closest( 'form' ).find( 'input[name="form_id"]' ).val();
1163 + jQuery( captcha ).closest( '.frm_form_field .frm_primary_label' ).hide();
2232 1164 params.callback = function( token ) {
2233 1165 frmFrontForm.afterRecaptcha( token, formID );
2234 1166 };
2235 1167 }
2236 1168
2237 - const activeCaptcha = getSelectedCaptcha( captchaSelector );
2238 - const captchaContainer = typeof turnstile !== 'undefined' && turnstile === activeCaptcha ? `#${ captcha.id }` : captcha.id;
2239 - const captchaID = activeCaptcha.render( captchaContainer, params );
1169 + recaptchaID = grecaptcha.render( captcha.id, params );
2240 1170
2241 - captcha.setAttribute( 'data-rid', captchaID );
2242 -
2243 - maybeFixCaptchaLabel( captcha );
1171 + captcha.setAttribute( 'data-rid', recaptchaID );
2244 1172 },
2245 1173
2246 - afterSingleRecaptcha() {
2247 - const recaptcha = document.querySelector( '.frm-show-form .g-recaptcha' );
2248 - const object = recaptcha ? recaptcha.closest( 'form' ) : null;
1174 + afterSingleRecaptcha: function() {
1175 + var object = jQuery( '.frm-show-form .g-recaptcha' ).closest( 'form' )[0];
2249 1176 frmFrontForm.submitFormNow( object );
2250 1177 },
2251 1178
2252 - afterRecaptcha( _, formID ) {
2253 - const object = document.querySelector( `#frm_form_${ formID }_container form` );
1179 + afterRecaptcha: function( token, formID ) {
1180 + var object = jQuery( '#frm_form_' + formID + '_container form' )[0];
2254 1181 frmFrontForm.submitFormNow( object );
2255 1182 },
2256 1183
2257 - submitForm( e ) {
1184 + submitForm: function( e ) {
2258 1185 frmFrontForm.submitFormManual( e, this );
2259 1186 },
2260 1187
2261 - /**
2262 - * @param {Event} e
2263 - * @param {HTMLElement} object The form object that is being submitted.
2264 - * @return {void}
2265 - */
2266 - submitFormManual( e, object ) {
2267 - if ( document.body.classList.contains( 'wp-admin' ) && ! object.closest( '.frmapi-form' ) ) {
1188 + submitFormManual: function( e, object ) {
1189 + var isPro, errors,
1190 + invisibleRecaptcha = hasInvisibleRecaptcha( object ),
1191 + classList = object.className.trim().split( /\s+/gi );
1192 +
1193 + if ( classList && invisibleRecaptcha.length < 1 ) {
1194 + isPro = classList.indexOf( 'frm_pro_form' ) > -1;
1195 + if ( ! isPro ) {
1196 + return;
1197 + }
1198 + }
1199 +
1200 + if ( jQuery( 'body' ).hasClass( 'wp-admin' ) && jQuery( object ).closest( '.frmapi-form' ).length < 1 ) {
2268 1201 return;
2269 1202 }
2270 1203
2271 1204 e.preventDefault();
2272 1205
2273 - if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' && ! frmProForm.submitAllowed( object ) ) {
2274 - return;
1206 + if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' ) {
1207 + if ( ! frmProForm.submitAllowed( object ) ) {
1208 + return;
1209 + }
2275 1210 }
2276 1211
2277 - const errors = frmFrontForm.validateFormSubmit( object );
2278 - if ( Object.keys( errors ).length !== 0 ) {
2279 - return;
2280 - }
2281 -
2282 - const invisibleRecaptcha = hasInvisibleRecaptcha( object );
2283 -
2284 - if ( invisibleRecaptcha ) {
1212 + if ( invisibleRecaptcha.length ) {
2285 1213 showLoadingIndicator( jQuery( object ) );
2286 1214 executeInvisibleRecaptcha( invisibleRecaptcha );
2287 1215 } else {
2288 - showSubmitLoading( jQuery( object ) );
2289 1216
2290 - frmFrontForm.submitFormNow( object );
1217 + errors = frmFrontForm.validateFormSubmit( object );
1218 +
1219 + if ( Object.keys( errors ).length === 0 ) {
1220 + showSubmitLoading( jQuery( object ) );
1221 +
1222 + frmFrontForm.submitFormNow( object, classList );
1223 + }
2291 1224 }
2292 1225 },
2293 1226
2294 - submitFormNow( object ) {
2295 - let hasFileFields;
2296 - let antispamInput;
2297 - const classList = object.className.trim().split( /\s+/gi );
1227 + submitFormNow: function( object ) {
1228 + var hasFileFields, antispamInput,
1229 + classList = object.className.trim().split( /\s+/gi );
2298 1230
2299 1231 if ( object.hasAttribute( 'data-token' ) && null === object.querySelector( '[name="antispam_token"]' ) ) {
2300 1232 // include the antispam token on form submit.
2301 1233 antispamInput = document.createElement( 'input' );
@@ -2301,24 +1233,17 @@
2301 1233 antispamInput = document.createElement( 'input' );
2302 1234 antispamInput.type = 'hidden';
2303 1235 antispamInput.name = 'antispam_token';
2304 1236 antispamInput.value = object.getAttribute( 'data-token' );
2305 - object.append( antispamInput );
1237 + object.appendChild( antispamInput );
2306 1238 }
2307 1239
2308 - // Add a unique ID, used for duplicate checks.
2309 - const uniqueIDInput = document.createElement( 'input' );
2310 - uniqueIDInput.type = 'hidden';
2311 - uniqueIDInput.name = 'unique_id';
2312 - uniqueIDInput.value = getUniqueKey();
2313 - object.append( uniqueIDInput );
2314 -
2315 - if ( classList.includes( 'frm_ajax_submit' ) ) {
2316 - const fileInputs = object.querySelectorAll( 'input[type="file"]' );
2317 - hasFileFields = Array.from( fileInputs ).filter( input => !! input.value ).length;
1240 + if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) {
1241 + hasFileFields = jQuery( object ).find( 'input[type="file"]' ).filter( function() {
1242 + return !! this.value;
1243 + }).length;
2318 1244 if ( hasFileFields < 1 ) {
2319 - const actionInput = object.querySelector( 'input[name="frm_action"]' );
2320 - const action = actionInput ? actionInput.value : '';
1245 + action = jQuery( object ).find( 'input[name="frm_action"]' ).val();
2321 1246 frmFrontForm.checkFormErrors( object, action );
2322 1247 } else {
2323 1248 object.submit();
2324 1249 }
@@ -2326,16 +1251,10 @@
2326 1251 object.submit();
2327 1252 }
2328 1253 },
2329 1254
2330 - /**
2331 - * @param {HTMLElement|Object} object Form object. This might be a jQuery object.
2332 - *
2333 - * @return {Array} List of errors.
2334 - */
2335 - validateFormSubmit( object ) {
2336 - const form = object instanceof jQuery ? object.get( 0 ) : object;
2337 - if ( typeof tinyMCE !== 'undefined' && form?.querySelector( '.wp-editor-wrap' ) ) {
1255 + validateFormSubmit: function( object ) {
1256 + if ( typeof tinyMCE !== 'undefined' && jQuery( object ).find( '.wp-editor-wrap' ).length ) {
2338 1257 tinyMCE.triggerSave();
2339 1258 }
2340 1259
2341 1260 jsErrors = [];
@@ -2350,23 +1269,16 @@
2350 1269
2351 1270 return jsErrors;
2352 1271 },
2353 1272
2354 - /**
2355 - * @param {HTMLElement|Object} object Form object. This might be a jQuery object.
2356 - * @return {Array} List of errors.
2357 - */
2358 - getAjaxFormErrors( object ) {
2359 - let customErrors;
2360 - let key;
2361 - const form = object instanceof jQuery ? object.get( 0 ) : object;
1273 + getAjaxFormErrors: function( object ) {
1274 + var customErrors, key;
2362 1275
2363 1276 jsErrors = validateForm( object );
2364 1277 if ( typeof frmThemeOverride_jsErrors === 'function' ) { // eslint-disable-line camelcase
2365 - const actionInput = form ? form.querySelector( 'input[name="frm_action"]' ) : null;
2366 - const action = actionInput ? actionInput.value : '';
1278 + action = jQuery( object ).find( 'input[name="frm_action"]' ).val();
2367 1279 customErrors = frmThemeOverride_jsErrors( action, object );
2368 - if ( Object.keys( customErrors ).length ) {
1280 + if ( Object.keys( customErrors ).length ) {
2369 1281 for ( key in customErrors ) {
2370 1282 jsErrors[ key ] = customErrors[ key ];
2371 1283 }
2372 1284 }
@@ -2371,30 +1283,20 @@
2371 1283 }
2372 1284 }
2373 1285 }
2374 1286
2375 - triggerCustomEvent( document, 'frm_get_ajax_form_errors', {
2376 - formEl: object,
2377 - errors: jsErrors
2378 - } );
2379 -
2380 1287 return jsErrors;
2381 1288 },
2382 1289
2383 - /**
2384 - * @param {HTMLElement|Object} object Form object. This might be a jQuery object.
2385 - * @return {void}
2386 - */
2387 - addAjaxFormErrors( object ) {
2388 - let key;
2389 - const form = object instanceof jQuery ? object.get( 0 ) : object;
1290 + addAjaxFormErrors: function( object ) {
1291 + var key, $fieldCont;
2390 1292 removeAllErrors();
2391 1293
2392 1294 for ( key in jsErrors ) {
2393 - const fieldCont = form ? form.querySelector( `#frm_field_${ key }_container` ) : null;
1295 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
2394 1296
2395 - if ( fieldCont ) {
2396 - addFieldError( fieldCont, key, jsErrors );
1297 + if ( $fieldCont.length ) {
1298 + addFieldError( $fieldCont, key, jsErrors );
2397 1299 } else {
2398 1300 // we are unable to show the error, so remove it
2399 1301 delete jsErrors[ key ];
2400 1302 }
@@ -2403,33 +1305,39 @@
2403 1305 scrollToFirstField( object );
2404 1306 checkForErrorsAndMaybeSetFocus();
2405 1307 },
2406 1308
2407 - checkFormErrors: getFormErrors,
2408 - checkRequiredField,
2409 - showSubmitLoading,
2410 - removeSubmitLoading,
1309 + checkFormErrors: function( object, action ) {
1310 + getFormErrors( object, action );
1311 + },
2411 1312
2412 - scrollToID( id ) {
2413 - const object = jQuery( document.getElementById( id ) );
2414 - frmFrontForm.scrollMsg( object, false );
1313 + checkRequiredField: function( field, errors ) {
1314 + return checkRequiredField( field, errors );
2415 1315 },
2416 1316
2417 - scrollMsg( id, object, animate ) {
2418 - let newPos;
2419 - let screenTop;
2420 - let screenBottom;
2421 - let scrollObj = '';
1317 + showSubmitLoading: function( $object ) {
1318 + showSubmitLoading( $object );
1319 + },
2422 1320
2423 - if ( object === undefined ) {
2424 - scrollObj = jQuery( document.getElementById( `frm_form_${ id }_container` ) );
1321 + removeSubmitLoading: function( $object, enable, processesRunning ) {
1322 + removeSubmitLoading( $object, enable, processesRunning );
1323 + },
1324 +
1325 + scrollToID: function( id ) {
1326 + var object = jQuery( document.getElementById( id ) );
1327 + frmFrontForm.scrollMsg( object, false );
1328 + },
1329 +
1330 + scrollMsg: function( id, object, animate ) {
1331 + var newPos, m, b, screenTop, screenBottom,
1332 + scrollObj = '';
1333 + if ( typeof object === 'undefined' ) {
1334 + scrollObj = jQuery( document.getElementById( 'frm_form_' + id + '_container' ) );
2425 1335 if ( scrollObj.length < 1 ) {
2426 1336 return;
2427 1337 }
2428 1338 } else if ( typeof id === 'string' ) {
2429 - const formEl = object instanceof jQuery ? object.get( 0 ) : object;
2430 - const fieldEl = formEl ? formEl.querySelector( `#frm_field_${ id }_container` ) : null;
2431 - scrollObj = fieldEl ? jQuery( fieldEl ) : jQuery();
1339 + scrollObj = jQuery( object ).find( '#frm_field_' + id + '_container' );
2432 1340 } else {
2433 1341 scrollObj = id;
2434 1342 }
2435 1343
@@ -2439,12 +1347,12 @@
2439 1347 return;
2440 1348 }
2441 1349 newPos = newPos - frm_js.offset;
2442 1350
2443 - const docMarginTop = getComputedStyle( document.documentElement ).marginTop;
2444 - const bodyMarginTop = getComputedStyle( document.body ).marginTop;
2445 - if ( docMarginTop || bodyMarginTop ) {
2446 - newPos = newPos - parseInt( docMarginTop ) - parseInt( bodyMarginTop );
1351 + m = jQuery( 'html' ).css( 'margin-top' );
1352 + b = jQuery( 'body' ).css( 'margin-top' );
1353 + if ( m || b ) {
1354 + newPos = newPos - parseInt( m ) - parseInt( b );
2447 1355 }
2448 1356
2449 1357 if ( newPos && window.innerHeight ) {
2450 1358 screenTop = document.documentElement.scrollTop || document.body.scrollTop;
@@ -2451,12 +1359,12 @@
2451 1359 screenBottom = screenTop + window.innerHeight;
2452 1360
2453 1361 if ( newPos > screenBottom || newPos < screenTop ) {
2454 1362 // Not in view
2455 - if ( animate === undefined ) {
2456 - document.documentElement.scrollTop = newPos;
1363 + if ( typeof animate === 'undefined' ) {
1364 + jQuery( window ).scrollTop( newPos );
2457 1365 } else {
2458 - animateScroll( screenTop, newPos, 500 );
1366 + jQuery( 'html,body' ).animate({ scrollTop: newPos }, 500 );
2459 1367 }
2460 1368 return false;
2461 1369 }
2462 1370 }
@@ -2461,13 +1369,13 @@
2461 1369 }
2462 1370 }
2463 1371 },
2464 1372
2465 - fieldValueChanged( e ) {
1373 + fieldValueChanged: function( e ) {
2466 1374 /*jshint validthis:true */
2467 1375
2468 - const fieldId = frmFrontForm.getFieldId( this, false );
2469 - if ( ! fieldId ) {
1376 + var fieldId = frmFrontForm.getFieldId( this, false );
1377 + if ( ! fieldId || typeof fieldId === 'undefined' ) {
2470 1378 return;
2471 1379 }
2472 1380
2473 1381 if ( e.frmTriggered && e.frmTriggered == fieldId ) {
@@ -2473,9 +1381,9 @@
2473 1381 if ( e.frmTriggered && e.frmTriggered == fieldId ) {
2474 1382 return;
2475 1383 }
2476 1384
2477 - jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ] );
1385 + jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]);
2478 1386
2479 1387 if ( e.selfTriggered !== true ) {
2480 1388 maybeValidateChange( this );
2481 1389 }
@@ -2480,10 +1388,56 @@
2480 1388 maybeValidateChange( this );
2481 1389 }
2482 1390 },
2483 1391
2484 - escapeHtml( text ) {
2485 - console.warn( 'DEPRECATED: function frmFrontForm.escapeHtml in v6.17' );
1392 + savingDraft: function( object ) {
1393 + console.warn( 'DEPRECATED: function frmFrontForm.savingDraft in v3.0 use frmProForm.savingDraft' );
1394 + if ( typeof frmProForm !== 'undefined' ) {
1395 + return frmProForm.savingDraft( object );
1396 + }
1397 + },
1398 +
1399 + goingToPreviousPage: function( object ) {
1400 + console.warn( 'DEPRECATED: function frmFrontForm.goingToPreviousPage in v3.0 use frmProForm.goingToPreviousPage' );
1401 + if ( typeof frmProForm !== 'undefined' ) {
1402 + return frmProForm.goingToPreviousPage( object );
1403 + }
1404 + },
1405 +
1406 + hideOrShowFields: function() {
1407 + console.warn( 'DEPRECATED: function frmFrontForm.hideOrShowFields in v3.0 use frmProForm.hideOrShowFields' );
1408 + if ( typeof frmProForm !== 'undefined' ) {
1409 + frmProForm.hideOrShowFields();
1410 + }
1411 + },
1412 +
1413 + hidePreviouslyHiddenFields: function() {
1414 + console.warn( 'DEPRECATED: function frmFrontForm.hidePreviouslyHiddenFields in v3.0 use frmProForm.hidePreviouslyHiddenFields' );
1415 + if ( typeof frmProForm !== 'undefined' ) {
1416 + frmProForm.hidePreviouslyHiddenFields();
1417 + }
1418 + },
1419 +
1420 + checkDependentDynamicFields: function( ids ) {
1421 + console.warn( 'DEPRECATED: function frmFrontForm.checkDependentDynamicFields in v3.0 use frmProForm.checkDependentDynamicFields' );
1422 + if ( typeof frmProForm !== 'undefined' ) {
1423 + frmProForm.checkDependentDynamicFields( ids );
1424 + }
1425 + },
1426 +
1427 + checkDependentLookupFields: function( ids ) {
1428 + console.warn( 'DEPRECATED: function frmFrontForm.checkDependentLookupFields in v3.0 use frmProForm.checkDependentLookupFields' );
1429 + if ( typeof frmProForm !== 'undefined' ) {
1430 + frmProForm.checkDependentLookupFields( ids );
1431 + }
1432 + },
1433 +
1434 + loadGoogle: function() {
1435 + console.warn( 'DEPRECATED: function frmFrontForm.loadGoogle in v3.0 use frmProForm.loadGoogle' );
1436 + frmProForm.loadGoogle();
1437 + },
1438 +
1439 + escapeHtml: function( text ) {
2486 1440 return text
2487 1441 .replace( /&/g, '&amp;' )
2488 1442 .replace( /</g, '&lt;' )
2489 1443 .replace( />/g, '&gt;' )
@@ -2490,82 +1444,97 @@
2490 1444 .replace( /"/g, '&quot;' )
2491 1445 .replace( /'/g, '&#039;' );
2492 1446 },
2493 1447
2494 - triggerCustomEvent,
2495 - documentOn
1448 + invisible: function( classes ) {
1449 + jQuery( classes ).css( 'visibility', 'hidden' );
1450 + },
1451 +
1452 + visible: function( classes ) {
1453 + jQuery( classes ).css( 'visibility', 'visible' );
1454 + }
2496 1455 };
2497 1456 }
1457 +frmFrontForm = frmFrontFormJS();
2498 1458
2499 -window.frmFrontForm = frmFrontFormJS();
2500 -
2501 1459 jQuery( document ).ready( function() {
2502 1460 frmFrontForm.init();
2503 -} );
1461 +});
2504 1462
2505 1463 function frmRecaptcha() {
2506 - frmCaptcha( '.frm-g-recaptcha' );
1464 + var c, cl,
1465 + captchas = jQuery( '.frm-g-recaptcha' );
1466 + for ( c = 0, cl = captchas.length; c < cl; c++ ) {
1467 + frmFrontForm.renderRecaptcha( captchas[c]);
1468 + }
2507 1469 }
2508 1470
2509 -function frmHcaptcha() {
2510 - frmCaptcha( '.h-captcha' );
1471 +function frmAfterRecaptcha( token ) {
1472 + frmFrontForm.afterSingleRecaptcha( token );
2511 1473 }
2512 1474
2513 -function frmTurnstile() {
2514 - frmCaptcha( '.frm-cf-turnstile' );
1475 +function frmUpdateField( entryId, fieldId, value, message, num ) {
1476 + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' );
1477 + jQuery.ajax({
1478 + type: 'POST',
1479 + url: frm_js.ajax_url,
1480 + data: {
1481 + action: 'frm_entries_update_field_ajax',
1482 + entry_id: entryId,
1483 + field_id: fieldId,
1484 + value: value,
1485 + nonce: frm_js.nonce
1486 + },
1487 + success: function() {
1488 + if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) {
1489 + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' );
1490 + } else {
1491 + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).replaceWith( message );
1492 + }
1493 + }
1494 + });
2515 1495 }
2516 1496
2517 -function frmCaptcha( captchaSelector ) {
2518 - if ( '.h-captcha' === captchaSelector ) {
2519 - // hCaptcha is still rendered implicitly, so we only want to handle the label and exit early.
2520 - // Match the hcaptcha labels to the hcaptcha response fields.
2521 - const captchaLabels = document.querySelectorAll( 'label[for="h-captcha-response"]' );
2522 - if ( captchaLabels.length ) {
2523 - captchaLabels.forEach( label => {
2524 - const captchaResponse = label.closest( 'form' )?.querySelector( '[name="h-captcha-response"]' );
2525 - if ( captchaResponse ) {
2526 - label.htmlFor = captchaResponse.id;
2527 - }
2528 - } );
1497 +function frmDeleteEntry( entryId, prefix ) {
1498 + console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' );
1499 + jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' );
1500 + jQuery.ajax({
1501 + type: 'POST',
1502 + url: frm_js.ajax_url,
1503 + data: {
1504 + action: 'frm_entries_destroy',
1505 + entry: entryId,
1506 + nonce: frm_js.nonce
1507 + },
1508 + success: function( html ) {
1509 + if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) {
1510 + jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' );
1511 + } else {
1512 + jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( html );
1513 + }
2529 1514 }
2530 - return;
2531 - }
2532 -
2533 - let c;
2534 - const captchas = document.querySelectorAll( captchaSelector );
2535 - const cl = captchas.length;
2536 - for ( c = 0; c < cl; c++ ) {
2537 - const closestForm = captchas[ c ].closest( 'form' );
2538 - const formIsVisible = closestForm && closestForm.offsetParent !== null;
2539 - const captcha = captchas[ c ];
2540 - if ( ! formIsVisible ) {
2541 - // If the form is not visible, try again later in 400ms.
2542 - // This fixes issues where the form fades visible on page load.
2543 - // Or when the form is inside of a modal.
2544 - const interval = setInterval(
2545 - function() {
2546 - if ( closestForm && closestForm.offsetParent !== null ) {
2547 - frmFrontForm.renderCaptcha( captcha, captchaSelector );
2548 - clearInterval( interval );
2549 - }
2550 - },
2551 - 400
2552 - );
2553 - continue;
2554 - }
2555 - frmFrontForm.renderCaptcha( captcha, captchaSelector );
2556 - }
1515 + });
2557 1516 }
2558 1517
2559 -function getSelectedCaptcha( captchaSelector ) {
2560 - if ( captchaSelector === '.frm-g-recaptcha' ) {
2561 - return grecaptcha;
2562 - }
2563 - if ( document.querySelector( '.frm-cf-turnstile' ) ) {
2564 - return turnstile;
2565 - }
2566 - return hcaptcha;
1518 +function frmOnSubmit( e ) {
1519 + console.warn( 'DEPRECATED: function frmOnSubmit in v2.0 use frmFrontForm.submitForm' );
1520 + frmFrontForm.submitForm( e, this );
2567 1521 }
2568 1522
2569 -function frmAfterRecaptcha( token ) {
2570 - frmFrontForm.afterSingleRecaptcha( token );
1523 +function frm_resend_email( entryId, formId ) { // eslint-disable-line camelcase
1524 + var $link = jQuery( document.getElementById( 'frm_resend_email' ) );
1525 + console.warn( 'DEPRECATED: function frm_resend_email in v2.0' );
1526 + $link.append( '<span class="spinner" style="display:inline"></span>' );
1527 + jQuery.ajax({
1528 + type: 'POST',
1529 + url: frm_js.ajax_url,
1530 + data: {
1531 + action: 'frm_entries_send_email',
1532 + entry_id: entryId,
1533 + form_id: formId,
1534 + nonce: frm_js.nonce
1535 + },
1536 + success: function( msg ) {
1537 + $link.replaceWith( msg );
1538 + }
1539 + });
2571 1540 }