PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
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 +771 -1769 6.315.3 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,97 +531,54 @@
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, data, success, error;
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' );
853 544
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 - }
545 + data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce;
859 546
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 -
547 + success = function( response ) {
548 + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
549 + $fieldCont, key, inCollapsedSection, frmTrigger,
550 + defaultResponse = { 'content': '', 'errors': {}, 'pass': false };
874 551 if ( response === null ) {
875 552 response = defaultResponse;
876 - } else {
877 - // Response is a string. Convert it to an object.
878 - response = response.replace( /^\s+|\s+$/g, '' );
879 - if ( response.indexOf( '{' ) === 0 ) {
880 - response = JSON.parse( response );
881 - } else {
882 - response = defaultResponse;
883 - }
884 553 }
885 554
886 - let willRedirect = false;
887 -
888 - if ( response.redirect !== undefined ) {
889 - if ( shouldTriggerEvent ) {
890 - triggerCustomEvent( object, 'frmSubmitEvent' );
891 - return;
892 - }
893 -
894 - if ( response.delay ) {
895 - setTimeout( function() {
896 - doRedirect( response );
897 - }, 1000 * response.delay );
898 - } else {
899 - doRedirect( response );
900 - }
901 -
902 - willRedirect = true;
555 + response = response.replace( /^\s+|\s+$/g, '' );
556 + if ( response.indexOf( '{' ) === 0 ) {
557 + response = JSON.parse( response );
558 + } else {
559 + response = defaultResponse;
903 560 }
904 561
905 - if ( 'string' === typeof response.content && response.content !== '' ) {
562 + if ( typeof response.redirect !== 'undefined' ) {
563 + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
564 + window.location = response.redirect;
565 + } else if ( response.content !== '' ) {
906 566 // the form or success message was returned
907 567
908 - if ( shouldTriggerEvent ) {
909 - triggerCustomEvent( object, 'frmSubmitEvent', { content: response.content } );
910 - return;
911 - }
912 -
913 568 removeSubmitLoading( jQuery( object ) );
914 569 if ( frm_js.offset != -1 ) {
915 570 frmFrontForm.scrollMsg( jQuery( object ), false );
916 571 }
917 -
918 - const formIdInput = object.querySelector( 'input[name="form_id"]' );
919 - const formID = formIdInput ? formIdInput.value : '';
572 + formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
920 573 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
574 + replaceContent = jQuery( object ).closest( '.frm_forms' );
922 575 removeAddedScripts( replaceContent, formID );
923 - const delay = maybeSlideOut( replaceContent, response.content );
576 + delay = maybeSlideOut( replaceContent, response.content );
924 577
925 578 setTimeout(
926 579 function() {
927 - afterFormSubmittedBeforeReplace( object, response );
580 + var container, input, previousInput;
928 581
929 582 replaceContent.replaceWith( response.content );
930 583
931 584 addUrlParam( response );
@@ -930,41 +583,49 @@
930 583
931 584 addUrlParam( response );
932 585
933 586 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 : '';
587 + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val();
588 + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val();
940 589 frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
941 590 }
942 591
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"]' );
596 +
597 + if ( previousInput.length ) {
598 + previousInput.replaceWith( input );
599 + } else {
600 + container.append( input );
601 + }
602 + }
603 +
943 604 afterFormSubmitted( object, response );
944 605 },
945 606 delay
946 607 );
947 - } else if ( response.errors !== undefined && Object.keys( response.errors ).length ) {
608 + } else if ( Object.keys( response.errors ).length ) {
948 609 // errors were returned
610 +
949 611 removeSubmitLoading( jQuery( object ), 'enable' );
950 612
951 613 //show errors
952 - let contSubmit = true;
614 + contSubmit = true;
953 615 removeAllErrors();
954 616
955 - let $fieldCont = null;
617 + $fieldCont = null;
956 618
957 - for ( const key in response.errors ) {
958 - const fieldContEl = object.querySelector( `#frm_field_${ key }_container` );
959 - $fieldCont = fieldContEl ? jQuery( fieldContEl ) : jQuery();
619 + for ( key in response.errors ) {
620 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
960 621
961 622 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
623 + if ( ! $fieldCont.is( ':visible' ) ) {
624 + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' );
964 625 if ( inCollapsedSection.length ) {
965 - let frmTrigger = inCollapsedSection.prev();
966 - if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) { // eslint-disable-line formidable/no-jquery-variable-methods
626 + frmTrigger = inCollapsedSection.prev();
627 + if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) {
967 628 // If the frmTrigger object is the section description, check to see if the previous element is the trigger
968 629 frmTrigger = frmTrigger.prev( '.frm_trigger' );
969 630 }
970 631 frmTrigger.trigger( 'click' );
@@ -970,9 +631,9 @@
970 631 frmTrigger.trigger( 'click' );
971 632 }
972 633 }
973 634
974 - if ( $fieldCont.is( ':visible' ) ) { // eslint-disable-line no-jquery/no-is
635 + if ( $fieldCont.is( ':visible' ) ) {
975 636 addFieldError( $fieldCont, key, response.errors );
976 637 contSubmit = false;
977 638 }
978 639 }
@@ -977,10 +638,11 @@
977 638 }
978 639 }
979 640 }
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 646 if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
985 647 if ( recaptchaID ) {
986 648 grecaptcha.reset( recaptchaID );
@@ -987,33 +649,23 @@
987 649 } else {
988 650 grecaptcha.reset();
989 651 }
990 652 }
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 - }
1002 -
1003 - jQuery( document ).trigger( 'frmFormErrors', [ object, response ] );
1004 -
1005 - fieldsets.forEach( field => field.classList.remove( 'frm_doing_ajax' ) );
657 + fieldset.removeClass( 'frm_doing_ajax' );
1006 658 scrollToFirstField( object );
1007 659
1008 660 if ( contSubmit ) {
1009 661 object.submit();
1010 662 } else {
1011 - object.insertAdjacentHTML( 'afterbegin', response.error_message );
663 + jQuery( object ).prepend( response.error_message );
1012 664 checkForErrorsAndMaybeSetFocus();
1013 665 }
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.
666 + } else {
667 + // there may have been a plugin conflict, or the form is not set to submit with ajax
1016 668
1017 669 showFileLoading( object );
1018 670
1019 671 object.submit();
@@ -1019,12 +671,10 @@
1019 671 object.submit();
1020 672 }
1021 673 };
1022 674
1023 - const error = function() {
1024 - object.querySelectorAll( 'input[type="submit"], input[type="button"]' ).forEach(
1025 - button => button.disabled = false
1026 - );
675 + error = function() {
676 + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
1027 677 object.submit();
1028 678 };
1029 679
1030 680 postToAjaxUrl( object, data, success, error );
@@ -1030,20 +680,22 @@
1030 680 postToAjaxUrl( object, data, success, error );
1031 681 }
1032 682
1033 683 function postToAjaxUrl( form, data, success, error ) {
1034 - let ajaxUrl = frm_js.ajax_url;
1035 - const action = form.getAttribute( 'action' );
684 + var ajaxUrl, action, ajaxParams;
1036 685
1037 - if ( 'string' === typeof action && action.includes( '?action=frm_forms_preview' ) ) {
1038 - ajaxUrl = action.split( '?action=frm_forms_preview' )[ 0 ];
686 + ajaxUrl = frm_js.ajax_url;
687 + action = form.getAttribute( 'action' );
688 +
689 + if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) {
690 + ajaxUrl = action.split( '?action=frm_forms_preview' )[0];
1039 691 }
1040 692
1041 - const ajaxParams = {
693 + ajaxParams = {
1042 694 type: 'POST',
1043 695 url: ajaxUrl,
1044 - data,
1045 - success
696 + data: data,
697 + success: success
1046 698 };
1047 699
1048 700 if ( 'function' === typeof error ) {
1049 701 ajaxParams.error = error;
@@ -1048,54 +700,34 @@
1048 700 if ( 'function' === typeof error ) {
1049 701 ajaxParams.error = error;
1050 702 }
1051 703
1052 - jQuery.ajax( ajaxParams ); // eslint-disable-line no-jquery/no-ajax
704 + jQuery.ajax( ajaxParams );
1053 705 }
1054 706
1055 707 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 ] );
708 + var formCompleted = jQuery( response.content ).find( '.frm_message' );
709 + if ( formCompleted.length ) {
710 + jQuery( document ).trigger( 'frmFormComplete', [ object, response ]);
1061 711 } else {
1062 - jQuery( document ).trigger( 'frmPageChanged', [ object, response ] );
712 + jQuery( document ).trigger( 'frmPageChanged', [ object, response ]);
1063 713 }
1064 714 }
1065 715
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 716 function removeAddedScripts( formContainer, formID ) {
1085 - const endReplace = document.querySelectorAll( `.frm_end_ajax_${ formID }` );
717 + var endReplace = jQuery( '.frm_end_ajax_' + formID );
1086 718 if ( endReplace.length ) {
1087 - formContainer.nextUntil( `.frm_end_ajax_${ formID }` ).remove();
1088 - endReplace.forEach( el => el.remove() );
719 + formContainer.nextUntil( '.frm_end_ajax_' + formID ).remove();
720 + endReplace.remove();
1089 721 }
1090 722 }
1091 723
1092 724 function maybeSlideOut( oldContent, newContent ) {
1093 - let c;
1094 - let newClass = 'frm_slideout';
1095 - if ( newContent.includes( ' frm_slide' ) ) {
725 + var c,
726 + newClass = 'frm_slideout';
727 + if ( newContent.indexOf( ' frm_slide' ) !== -1 ) {
1096 728 c = oldContent.children();
1097 - if ( newContent.includes( ' frm_going_back' ) ) {
729 + if ( newContent.indexOf( ' frm_going_back' ) !== -1 ) {
1098 730 newClass += ' frm_going_back';
1099 731 }
1100 732 c.removeClass( 'frm_going_back' );
1101 733 c.addClass( newClass );
@@ -1104,28 +736,30 @@
1104 736 return 0;
1105 737 }
1106 738
1107 739 function addUrlParam( response ) {
1108 - let url;
1109 - if ( history.pushState && response.page !== undefined ) {
740 + var url;
741 + if ( history.pushState && typeof response.page !== 'undefined' ) {
1110 742 url = addQueryVar( 'frm_page', response.page );
1111 - window.history.pushState( { html: response.html }, '', `?${ url }` );
743 + window.history.pushState({ 'html': response.html }, '', '?' + url );
1112 744 }
1113 745 }
1114 746
1115 747 function addQueryVar( key, value ) {
748 + var kvp, i, x;
749 +
1116 750 key = encodeURI( key );
1117 751 value = encodeURI( value );
1118 752
1119 - const kvp = document.location.search.substr( 1 ).split( '&' );
753 + kvp = document.location.search.substr( 1 ).split( '&' );
1120 754
1121 - let i = kvp.length;
755 + i = kvp.length;
1122 756 while ( i-- ) {
1123 - const x = kvp[ i ].split( '=' );
757 + x = kvp[i].split( '=' );
1124 758
1125 - if ( x[ 0 ] == key ) {
1126 - x[ 1 ] = value;
1127 - kvp[ i ] = x.join( '=' );
759 + if ( x[0] == key ) {
760 + x[1] = value;
761 + kvp[i] = x.join( '=' );
1128 762 break;
1129 763 }
1130 764 }
1131 765
@@ -1136,143 +770,69 @@
1136 770 return kvp.join( '&' );
1137 771 }
1138 772
1139 773 function addFieldError( $fieldCont, key, jsErrors ) {
1140 - const container = $fieldCont instanceof jQuery ? $fieldCont.get( 0 ) : $fieldCont;
774 + var input, id, describedBy, roleString;
775 + if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) {
776 + $fieldCont.addClass( 'frm_blank_field' );
777 + input = $fieldCont.find( 'input, select, textarea' );
778 + id = 'frm_error_field_' + key;
779 + describedBy = input.attr( 'aria-describedby' );
1141 780
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 ];
781 + if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase
782 + frmThemeOverride_frmPlaceError( key, jsErrors );
1158 783 } 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 );
784 + if ( -1 !== jsErrors[key].indexOf( '<div' ) ) {
785 + $fieldCont.append(
786 + jsErrors[key]
787 + );
788 + } else {
789 + roleString = frm_js.include_alert_role ? 'role="alert"' : '';
790 + $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' );
791 + }
1163 792
1164 - if ( input ) {
1165 - if ( ! describedBy ) {
793 + if ( typeof describedBy === 'undefined' ) {
1166 794 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 - }
795 + } else if ( describedBy.indexOf( id ) === -1 ) {
796 + describedBy = describedBy + ' ' + id;
1174 797 }
1175 - input.setAttribute( 'aria-describedby', describedBy );
798 + input.attr( 'aria-describedby', describedBy );
1176 799 }
1177 - }
800 + input.attr( 'aria-invalid', true );
801 + input.attr( 'aria-describedby', id );
1178 802
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 - }
803 + jQuery( document ).trigger( 'frmAddFieldError', [ $fieldCont, key, jsErrors ]);
1188 804 }
1189 -
1190 - jQuery( document ).trigger( 'frmAddFieldError', [ jQuery( container ), key, jsErrors ] );
1191 805 }
1192 806
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 - }
807 + function removeFieldError( $fieldCont ) {
808 + var errorMessage = $fieldCont.find( '.frm_error' ),
809 + errorId = errorMessage.attr( 'id' ),
810 + input = $fieldCont.find( 'input, select, textarea' ),
811 + describedBy = input.attr( 'aria-describedby' );
1207 812
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 - }
813 + $fieldCont.removeClass( 'frm_blank_field has-error' );
814 + errorMessage.remove();
815 + input.attr( 'aria-invalid', false );
816 + input.removeAttr( 'aria-describedby' );
1220 817
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 - }
818 + if ( typeof describedBy !== 'undefined' ) {
819 + describedBy = describedBy.replace( errorId, '' );
820 + input.attr( 'aria-describedby', describedBy );
1237 821 }
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 822 }
1253 823
1254 824 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() );
825 + jQuery( '.form-field' ).removeClass( 'frm_blank_field has-error' );
826 + jQuery( '.form-field .frm_error' ).replaceWith( '' );
827 + jQuery( '.frm_error_style' ).remove();
1260 828 }
1261 829
1262 - /**
1263 - * @param {HTMLElement|Object} object Form object.
1264 - * @return {void}
1265 - */
1266 830 function scrollToFirstField( object ) {
1267 - if ( 'function' === typeof object.get ) {
1268 - // Get the HTMLElement from a jQuery object.
1269 - object = object.get( 0 );
831 + var field = jQuery( object ).find( '.frm_blank_field' ).first();
832 + if ( field.length ) {
833 + frmFrontForm.scrollMsg( field, object, true );
1270 834 }
1271 - const field = object.querySelector( '.frm_blank_field' );
1272 - if ( field ) {
1273 - frmFrontForm.scrollMsg( jQuery( field ), object, true );
1274 - }
1275 835 }
1276 836
1277 837 function showSubmitLoading( $object ) {
1278 838 showLoadingIndicator( $object );
@@ -1280,9 +840,9 @@
1280 840 disableSaveDraft( $object );
1281 841 }
1282 842
1283 843 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
844 + if ( ! $object.hasClass( 'frm_loading_form' ) && ! $object.hasClass( 'frm_loading_prev' ) ) {
1285 845 addLoadingClass( $object );
1286 846 $object.trigger( 'frmStartFormLoading' );
1287 847 }
1288 848 }
@@ -1287,889 +847,320 @@
1287 847 }
1288 848 }
1289 849
1290 850 function addLoadingClass( $object ) {
1291 - const loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form';
851 + var loadingClass = isGoingToPrevPage( $object ) ? 'frm_loading_prev' : 'frm_loading_form';
1292 852
1293 - $object.addClass( loadingClass ); // eslint-disable-line no-jquery/no-class, formidable/no-jquery-variable-methods
853 + $object.addClass( loadingClass );
1294 854 }
1295 855
1296 856 function isGoingToPrevPage( $object ) {
1297 - return typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object );
857 + return ( typeof frmProForm !== 'undefined' && frmProForm.goingToPreviousPage( $object ) );
1298 858 }
1299 859
1300 - function removeSubmitLoading( _, enable, processesRunning ) {
860 + function removeSubmitLoading( $object, enable, processesRunning ) {
861 + var loadingForm;
862 +
1301 863 if ( processesRunning > 0 ) {
1302 864 return;
1303 865 }
1304 866
1305 - document.querySelectorAll( '.frm_loading_form' ).forEach( function( form ) {
1306 - form.classList.remove( 'frm_loading_form', 'frm_loading_prev' );
1307 - jQuery( form ).trigger( 'frmEndFormLoading' );
867 + loadingForm = jQuery( '.frm_loading_form' );
868 + loadingForm.removeClass( 'frm_loading_form' );
869 + loadingForm.removeClass( 'frm_loading_prev' );
1308 870
1309 - if ( enable === 'enable' ) {
1310 - enableSubmitButton( form );
1311 - enableSaveDraft( form );
1312 - }
1313 - } );
871 + loadingForm.trigger( 'frmEndFormLoading' );
872 +
873 + if ( enable === 'enable' ) {
874 + enableSubmitButton( loadingForm );
875 + enableSaveDraft( loadingForm );
876 + }
1314 877 }
1315 878
1316 879 function showFileLoading( object ) {
1317 - const loading = document.getElementById( 'frm_loading' );
1318 - if ( ! loading ) {
1319 - return;
880 + var fileval,
881 + loading = document.getElementById( 'frm_loading' );
882 + if ( loading !== null ) {
883 + fileval = jQuery( object ).find( 'input[type=file]' ).val();
884 + if ( typeof fileval !== 'undefined' && fileval !== '' ) {
885 + setTimeout( function() {
886 + jQuery( loading ).fadeIn( 'slow' );
887 + }, 2000 );
888 + }
1320 889 }
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 890 }
1330 891
1331 - /**********************************************
1332 - * General Helpers
1333 - *********************************************/
1334 -
1335 - function confirmClick() {
892 + function clearDefault() {
1336 893 /*jshint validthis:true */
1337 - const message = this.dataset.frmconfirm;
1338 - return confirm( message );
894 + toggleDefault( jQuery( this ), 'clear' );
1339 895 }
1340 896
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() {
897 + function replaceDefault() {
1347 898 /*jshint validthis:true */
1348 - const css = window.getComputedStyle( this ).boxShadow;
1349 - if ( css?.match( /inset/ ) ) {
1350 - this.remove();
1351 - }
899 + toggleDefault( jQuery( this ), 'replace' );
1352 900 }
1353 901
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;
902 + function toggleDefault( $thisField, e ) {
903 + // TODO: Fix this for a default value that is a number or array
904 + var thisVal,
905 + v = $thisField.data( 'frmval' ).replace( /(\n|\r\n)/g, '\r' );
906 + if ( v === '' || typeof v === 'undefined' ) {
907 + return false;
908 + }
909 + thisVal = $thisField.val().replace( /(\n|\r\n)/g, '\r' );
1361 910
1362 - const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1363 - comboInputsContainer.forEach( function( inputsContainer ) {
1364 - if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1365 - return;
911 + if ( 'replace' === e ) {
912 + if ( thisVal === '' ) {
913 + $thisField.addClass( 'frm_default' ).val( v );
1366 914 }
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;
915 + } else if ( thisVal == v ) {
916 + $thisField.removeClass( 'frm_default' ).val( '' );
1390 917 }
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 918 }
1401 919
1402 - function checkForErrorsAndMaybeSetFocus() {
1403 - if ( ! frm_js.focus_first_error ) {
1404 - return;
920 + function resendEmail() {
921 + /*jshint validthis:true */
922 + var $link = jQuery( this ),
923 + entryId = this.getAttribute( 'data-eid' ),
924 + formId = this.getAttribute( 'data-fid' ),
925 + label = $link.find( '.frm_link_label' );
926 + if ( label.length < 1 ) {
927 + label = $link;
1405 928 }
929 + label.append( '<span class="frm-wait"></span>' );
1406 930
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;
931 + jQuery.ajax({
932 + type: 'POST',
933 + url: frm_js.ajax_url,
934 + data: {
935 + action: 'frm_entries_send_email',
936 + entry_id: entryId,
937 + form_id: formId,
938 + nonce: frm_js.nonce
939 + },
940 + success: function( msg ) {
941 + var admin = document.getElementById( 'wpbody' );
942 + if ( admin === null ) {
943 + label.html( msg );
944 + } else {
945 + label.html( '' );
946 + $link.after( msg );
947 + }
1419 948 }
949 + });
950 + return false;
951 + }
1420 952
1421 - if ( maybeFocusOnComboSubField( element ) ) {
1422 - break;
1423 - }
953 + /**********************************************
954 + * General Helpers
955 + *********************************************/
1424 956
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 );
957 + function confirmClick() {
958 + /*jshint validthis:true */
959 + var message = jQuery( this ).data( 'frmconfirm' );
960 + return confirm( message );
1451 961 }
1452 962
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();
963 + function toggleDiv() {
964 + /*jshint validthis:true */
965 + var div = jQuery( this ).data( 'frmtoggle' );
966 + if ( jQuery( div ).is( ':visible' ) ) {
967 + jQuery( div ).slideUp( 'fast' );
1464 968 } else {
1465 - triggerCustomEvent( document, 'frmMaybeDelayFocus', { input } );
969 + jQuery( div ).slideDown( 'fast' );
1466 970 }
971 + return false;
1467 972 }
1468 973
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 - }
974 + /**********************************************
975 + * Fallback functions
976 + *********************************************/
1483 977
1484 - document.addEventListener( event, function( e ) {
1485 - let target;
978 + function addIndexOfFallbackForIE8() {
979 + var len, from;
1486 980
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;
981 + if ( ! Array.prototype.indexOf ) {
982 + Array.prototype.indexOf = function( elt /*, from*/ ) {
983 + len = this.length >>> 0;
984 +
985 + from = Number( arguments[1]) || 0;
986 + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from );
987 + if ( from < 0 ) {
988 + from += len;
1492 989 }
1493 - }
1494 - }, options );
1495 - }
1496 990
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' );
991 + for ( ; from < len; from++ ) {
992 + if ( from in this && this[from] === elt ) {
993 + return from;
1518 994 }
1519 - } else if ( firstOpt.textContent ) {
1520 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1521 - firstOpt.textContent = '';
1522 995 }
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;
996 + return -1;
997 + };
1580 998 }
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 999 }
1596 1000
1597 - function maybeClearCustomValidityMessage( event, field ) {
1598 - let key;
1599 - let isInvalid = false;
1600 -
1601 - if ( ! shouldUpdateValidityMessage( field ) ) {
1602 - return;
1001 + function addTrimFallbackForIE8() {
1002 + if ( typeof String.prototype.trim !== 'function' ) {
1003 + String.prototype.trim = function() {
1004 + return this.replace( /^\s+|\s+$/g, '' );
1005 + };
1603 1006 }
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 1007 }
1619 1008
1620 - function maybeShowNewTabFallbackMessage() {
1621 - if ( ! window.frmShowNewTabFallback ) {
1622 - return;
1623 - }
1009 + function addFilterFallbackForIE8() {
1010 + var t, len, res, thisp, i, val;
1624 1011
1625 - const messageEl = document.querySelector( `#frm_form_${ frmShowNewTabFallback.formId }_container .frm_message` );
1626 - if ( ! messageEl ) {
1627 - return;
1628 - }
1012 + if ( ! Array.prototype.filter ) {
1629 1013
1630 - messageEl.insertAdjacentHTML( 'beforeend', ` ${ frmShowNewTabFallback.message }` );
1631 - }
1014 + Array.prototype.filter = function( fun /*, thisp */ ) {
1632 1015
1633 - function setCustomValidityMessage() {
1634 - const forms = document.getElementsByClassName( 'frm-show-form' );
1635 - const { length } = forms;
1016 + if ( this === void 0 || this === null ) {
1017 + throw new TypeError();
1018 + }
1636 1019
1637 - for ( let index = 0; index < length; ++index ) {
1638 - forms[ index ].addEventListener(
1639 - 'invalid',
1640 - function( event ) {
1641 - const { target } = event;
1020 + t = Object( this );
1021 + len = t.length >>> 0;
1022 + if ( typeof fun !== 'function' ) {
1023 + throw new TypeError();
1024 + }
1642 1025
1643 - if ( shouldUpdateValidityMessage( target ) ) {
1644 - target.setCustomValidity( target.dataset.invmsg );
1026 + res = [];
1027 + thisp = arguments[1];
1028 + for ( i = 0; i < len; i++ ) {
1029 + if ( i in t ) {
1030 + val = t[i]; // in case fun mutates this
1031 + if ( fun.call( thisp, val, i, t ) ) {
1032 + res.push( val );
1033 + }
1645 1034 }
1646 - },
1647 - true
1648 - );
1649 - }
1650 - }
1035 + }
1651 1036
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;
1037 + return res;
1038 + };
1671 1039 }
1672 - window.hcaptcha = null;
1673 1040 }
1674 1041
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 - }
1042 + function addKeysFallbackForIE8() {
1043 + var keys, i;
1687 1044
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 - }
1045 + if ( ! Object.keys ) {
1046 + Object.keys = function( obj ) {
1047 + keys = [];
1703 1048
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 - }
1049 + for ( i in obj ) {
1050 + if ( obj.hasOwnProperty( i ) ) {
1051 + keys.push( i );
1052 + }
1053 + }
1714 1054
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;
1055 + return keys;
1056 + };
1729 1057 }
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 1058 }
1738 1059
1739 1060 /**
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.
1061 + * Check for -webkit-box-shadow css value for input:-webkit-autofill selector.
1062 + * If this is a match, the User is autofilling the input on a Webkit browser.
1063 + * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
1744 1064 */
1745 - function checkQuantityFieldMinMax( input ) {
1746 - if ( '' === input.value ) {
1747 - // Leave the value if it is empty.
1748 - return 0;
1065 + function onHoneypotFieldChange() {
1066 + var css = jQuery( this ).css( 'box-shadow' );
1067 + if ( css.match( /inset/ ) ) {
1068 + this.parentNode.removeChild( this );
1749 1069 }
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 1070 }
1774 1071
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 1072 /**
1784 - * Calculates the total price.
1073 + * Focus on the first sub field when clicking to the primary label of combo field.
1785 1074 *
1786 - * @param {Event|undefined} e The event object.
1787 - * @return {void}
1075 + * @since 4.10.02
1788 1076 */
1789 - function calcProductsTotal( e ) {
1790 - if ( 'object' === typeof frmProForm ) {
1791 - // Pro is installed, use the Pro JS.
1792 - return;
1793 - }
1077 + function changeFocusWhenClickComboFieldLabel() {
1078 + let label;
1794 1079
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 ) {
1080 + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1081 + comboInputsContainer.forEach( function( inputsContainer ) {
1082 + if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1811 1083 return;
1812 1084 }
1813 1085
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;
1086 + label = inputsContainer.closest( '.frm_form_field' ).querySelector( '.frm_primary_label' );
1087 + if ( ! label ) {
1873 1088 return;
1874 1089 }
1875 1090
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 - } );
1091 + label.addEventListener( 'click', function( e ) {
1092 + inputsContainer.querySelector( '.frm_form_field:first-child input, .frm_form_field:first-child select, .frm_form_field:first-child textarea' ).focus();
1093 + });
1094 + });
1882 1095 }
1883 1096
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;
1097 + function checkForErrorsAndMaybeSetFocus() {
1098 + var errors, element, timeoutCallback;
1893 1099
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 );
1100 + if ( ! frm_js.focus_first_error ) {
1101 + return;
1905 1102 }
1906 1103
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 );
1104 + errors = document.querySelectorAll( '.frm_form_field .frm_error' );
1105 + if ( ! errors.length ) {
1106 + return;
1925 1107 }
1926 1108
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;
1109 + element = errors[0];
1110 + do {
1111 + element = element.previousSibling;
1112 + if ( -1 !== [ 'input', 'select', 'textarea' ].indexOf( element.nodeName.toLowerCase() ) ) {
1113 + element.focus();
1114 + break;
1999 1115 }
2000 1116
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';
1117 + if ( 'undefined' !== typeof element.classList ) {
1118 + if ( element.classList.contains( 'html-active' ) ) {
1119 + timeoutCallback = function() {
1120 + var textarea = element.querySelector( 'textarea' );
1121 + if ( null !== textarea ) {
1122 + textarea.focus();
1123 + }
1124 + };
1125 + } else if ( element.classList.contains( 'tmce-active' ) ) {
1126 + timeoutCallback = function() {
1127 + tinyMCE.activeEditor.focus();
1128 + };
2110 1129 }
2111 1130
2112 - for ( let n = 2; n < currency.decimals; ++n ) {
2113 - price += '0';
1131 + if ( 'function' === typeof timeoutCallback ) {
1132 + setTimeout( timeoutCallback, 0 );
1133 + break;
2114 1134 }
2115 1135 }
2116 - }
2117 -
2118 - return price.replace( '.', currency.decimal_separator );
1136 + } while ( element.previousSibling );
2119 1137 }
2120 1138
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 );
1139 + return {
1140 + init: function() {
1141 + jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
1142 + jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
2135 1143
2136 - if ( options.thousand_separator ) {
2137 - split[ 0 ] = split[ 0 ].replace( /\B(?=(\d{3})+(?!\d))/g, options.thousand_separator );
2138 - }
1144 + jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
1145 + if ( jQuery( this ).val() === '' ) {
1146 + jQuery( this ).trigger( 'blur' );
1147 + }
1148 + });
2139 1149
2140 - return split.join( options.decimal_separator );
2141 - }
1150 + jQuery( document ).on( 'focus', '.frm_toggle_default', clearDefault );
1151 + jQuery( document ).on( 'blur', '.frm_toggle_default', replaceDefault );
1152 + jQuery( '.frm_toggle_default' ).trigger( 'blur' );
2142 1153
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 - }
1154 + jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail );
2161 1155
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 1156 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 );
1157 + 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 1158
2169 - jQuery( document ).on( 'change', '.frm_verify[id^=field_]', onHoneypotFieldChange );
1159 + jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange );
2170 1160
2171 1161 jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick );
1162 + jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv );
2172 1163
2173 1164 checkForErrorsAndMaybeSetFocus();
2174 1165
2175 1166 // Focus on the first sub field when clicking to the primary label of combo field.
@@ -2174,128 +1165,102 @@
2174 1165
2175 1166 // Focus on the first sub field when clicking to the primary label of combo field.
2176 1167 changeFocusWhenClickComboFieldLabel();
2177 1168
2178 - initFloatingLabels();
2179 - maybeShowNewTabFallbackMessage();
1169 + // Add fallbacks for the beloved IE8
1170 + addIndexOfFallbackForIE8();
1171 + addTrimFallbackForIE8();
1172 + addFilterFallbackForIE8();
1173 + addKeysFallbackForIE8();
1174 + },
2180 1175
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();
1176 + getFieldId: function( field, fullID ) {
1177 + return getFieldId( field, fullID );
2200 1178 },
2201 1179
2202 - getFieldId,
1180 + renderRecaptcha: function( captcha ) {
1181 + var formID, recaptchaID,
1182 + size = captcha.getAttribute( 'data-size' ),
1183 + rendered = captcha.getAttribute( 'data-rid' ) !== null,
1184 + params = {
1185 + 'sitekey': captcha.getAttribute( 'data-sitekey' ),
1186 + 'size': size,
1187 + 'theme': captcha.getAttribute( 'data-theme' )
1188 + };
2203 1189
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 1190 if ( rendered ) {
2214 1191 return;
2215 1192 }
2216 1193
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 1194 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 -
1195 + formID = jQuery( captcha ).closest( 'form' ).find( 'input[name="form_id"]' ).val();
1196 + jQuery( captcha ).closest( '.frm_form_field .frm_primary_label' ).hide();
2232 1197 params.callback = function( token ) {
2233 1198 frmFrontForm.afterRecaptcha( token, formID );
2234 1199 };
2235 1200 }
2236 1201
2237 - const activeCaptcha = getSelectedCaptcha( captchaSelector );
2238 - const captchaContainer = typeof turnstile !== 'undefined' && turnstile === activeCaptcha ? `#${ captcha.id }` : captcha.id;
2239 - const captchaID = activeCaptcha.render( captchaContainer, params );
1202 + recaptchaID = grecaptcha.render( captcha.id, params );
2240 1203
2241 - captcha.setAttribute( 'data-rid', captchaID );
2242 -
2243 - maybeFixCaptchaLabel( captcha );
1204 + captcha.setAttribute( 'data-rid', recaptchaID );
2244 1205 },
2245 1206
2246 - afterSingleRecaptcha() {
2247 - const recaptcha = document.querySelector( '.frm-show-form .g-recaptcha' );
2248 - const object = recaptcha ? recaptcha.closest( 'form' ) : null;
1207 + afterSingleRecaptcha: function() {
1208 + var object = jQuery( '.frm-show-form .g-recaptcha' ).closest( 'form' )[0];
2249 1209 frmFrontForm.submitFormNow( object );
2250 1210 },
2251 1211
2252 - afterRecaptcha( _, formID ) {
2253 - const object = document.querySelector( `#frm_form_${ formID }_container form` );
1212 + afterRecaptcha: function( token, formID ) {
1213 + var object = jQuery( '#frm_form_' + formID + '_container form' )[0];
2254 1214 frmFrontForm.submitFormNow( object );
2255 1215 },
2256 1216
2257 - submitForm( e ) {
1217 + submitForm: function( e ) {
2258 1218 frmFrontForm.submitFormManual( e, this );
2259 1219 },
2260 1220
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' ) ) {
1221 + submitFormManual: function( e, object ) {
1222 + var isPro, errors,
1223 + invisibleRecaptcha = hasInvisibleRecaptcha( object ),
1224 + classList = object.className.trim().split( /\s+/gi );
1225 +
1226 + if ( classList && invisibleRecaptcha.length < 1 ) {
1227 + isPro = classList.indexOf( 'frm_pro_form' ) > -1;
1228 + if ( ! isPro ) {
1229 + return;
1230 + }
1231 + }
1232 +
1233 + if ( jQuery( 'body' ).hasClass( 'wp-admin' ) && jQuery( object ).closest( '.frmapi-form' ).length < 1 ) {
2268 1234 return;
2269 1235 }
2270 1236
2271 1237 e.preventDefault();
2272 1238
2273 - if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' && ! frmProForm.submitAllowed( object ) ) {
2274 - return;
1239 + if ( typeof frmProForm !== 'undefined' && typeof frmProForm.submitAllowed === 'function' ) {
1240 + if ( ! frmProForm.submitAllowed( object ) ) {
1241 + return;
1242 + }
2275 1243 }
2276 1244
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 ) {
1245 + if ( invisibleRecaptcha.length ) {
2285 1246 showLoadingIndicator( jQuery( object ) );
2286 1247 executeInvisibleRecaptcha( invisibleRecaptcha );
2287 1248 } else {
2288 - showSubmitLoading( jQuery( object ) );
2289 1249
2290 - frmFrontForm.submitFormNow( object );
1250 + errors = frmFrontForm.validateFormSubmit( object );
1251 +
1252 + if ( Object.keys( errors ).length === 0 ) {
1253 + showSubmitLoading( jQuery( object ) );
1254 +
1255 + frmFrontForm.submitFormNow( object, classList );
1256 + }
2291 1257 }
2292 1258 },
2293 1259
2294 - submitFormNow( object ) {
2295 - let hasFileFields;
2296 - let antispamInput;
2297 - const classList = object.className.trim().split( /\s+/gi );
1260 + submitFormNow: function( object ) {
1261 + var hasFileFields, antispamInput,
1262 + classList = object.className.trim().split( /\s+/gi );
2298 1263
2299 1264 if ( object.hasAttribute( 'data-token' ) && null === object.querySelector( '[name="antispam_token"]' ) ) {
2300 1265 // include the antispam token on form submit.
2301 1266 antispamInput = document.createElement( 'input' );
@@ -2301,24 +1266,17 @@
2301 1266 antispamInput = document.createElement( 'input' );
2302 1267 antispamInput.type = 'hidden';
2303 1268 antispamInput.name = 'antispam_token';
2304 1269 antispamInput.value = object.getAttribute( 'data-token' );
2305 - object.append( antispamInput );
1270 + object.appendChild( antispamInput );
2306 1271 }
2307 1272
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;
1273 + if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) {
1274 + hasFileFields = jQuery( object ).find( 'input[type="file"]' ).filter( function() {
1275 + return !! this.value;
1276 + }).length;
2318 1277 if ( hasFileFields < 1 ) {
2319 - const actionInput = object.querySelector( 'input[name="frm_action"]' );
2320 - const action = actionInput ? actionInput.value : '';
1278 + action = jQuery( object ).find( 'input[name="frm_action"]' ).val();
2321 1279 frmFrontForm.checkFormErrors( object, action );
2322 1280 } else {
2323 1281 object.submit();
2324 1282 }
@@ -2326,16 +1284,10 @@
2326 1284 object.submit();
2327 1285 }
2328 1286 },
2329 1287
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' ) ) {
1288 + validateFormSubmit: function( object ) {
1289 + if ( typeof tinyMCE !== 'undefined' && jQuery( object ).find( '.wp-editor-wrap' ).length ) {
2338 1290 tinyMCE.triggerSave();
2339 1291 }
2340 1292
2341 1293 jsErrors = [];
@@ -2350,23 +1302,16 @@
2350 1302
2351 1303 return jsErrors;
2352 1304 },
2353 1305
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;
1306 + getAjaxFormErrors: function( object ) {
1307 + var customErrors, key;
2362 1308
2363 1309 jsErrors = validateForm( object );
2364 1310 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 : '';
1311 + action = jQuery( object ).find( 'input[name="frm_action"]' ).val();
2367 1312 customErrors = frmThemeOverride_jsErrors( action, object );
2368 - if ( Object.keys( customErrors ).length ) {
1313 + if ( Object.keys( customErrors ).length ) {
2369 1314 for ( key in customErrors ) {
2370 1315 jsErrors[ key ] = customErrors[ key ];
2371 1316 }
2372 1317 }
@@ -2371,30 +1316,20 @@
2371 1316 }
2372 1317 }
2373 1318 }
2374 1319
2375 - triggerCustomEvent( document, 'frm_get_ajax_form_errors', {
2376 - formEl: object,
2377 - errors: jsErrors
2378 - } );
2379 -
2380 1320 return jsErrors;
2381 1321 },
2382 1322
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;
1323 + addAjaxFormErrors: function( object ) {
1324 + var key, $fieldCont;
2390 1325 removeAllErrors();
2391 1326
2392 1327 for ( key in jsErrors ) {
2393 - const fieldCont = form ? form.querySelector( `#frm_field_${ key }_container` ) : null;
1328 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
2394 1329
2395 - if ( fieldCont ) {
2396 - addFieldError( fieldCont, key, jsErrors );
1330 + if ( $fieldCont.length ) {
1331 + addFieldError( $fieldCont, key, jsErrors );
2397 1332 } else {
2398 1333 // we are unable to show the error, so remove it
2399 1334 delete jsErrors[ key ];
2400 1335 }
@@ -2403,33 +1338,39 @@
2403 1338 scrollToFirstField( object );
2404 1339 checkForErrorsAndMaybeSetFocus();
2405 1340 },
2406 1341
2407 - checkFormErrors: getFormErrors,
2408 - checkRequiredField,
2409 - showSubmitLoading,
2410 - removeSubmitLoading,
1342 + checkFormErrors: function( object, action ) {
1343 + getFormErrors( object, action );
1344 + },
2411 1345
2412 - scrollToID( id ) {
2413 - const object = jQuery( document.getElementById( id ) );
2414 - frmFrontForm.scrollMsg( object, false );
1346 + checkRequiredField: function( field, errors ) {
1347 + return checkRequiredField( field, errors );
2415 1348 },
2416 1349
2417 - scrollMsg( id, object, animate ) {
2418 - let newPos;
2419 - let screenTop;
2420 - let screenBottom;
2421 - let scrollObj = '';
1350 + showSubmitLoading: function( $object ) {
1351 + showSubmitLoading( $object );
1352 + },
2422 1353
2423 - if ( object === undefined ) {
2424 - scrollObj = jQuery( document.getElementById( `frm_form_${ id }_container` ) );
1354 + removeSubmitLoading: function( $object, enable, processesRunning ) {
1355 + removeSubmitLoading( $object, enable, processesRunning );
1356 + },
1357 +
1358 + scrollToID: function( id ) {
1359 + var object = jQuery( document.getElementById( id ) );
1360 + frmFrontForm.scrollMsg( object, false );
1361 + },
1362 +
1363 + scrollMsg: function( id, object, animate ) {
1364 + var newPos, m, b, screenTop, screenBottom,
1365 + scrollObj = '';
1366 + if ( typeof object === 'undefined' ) {
1367 + scrollObj = jQuery( document.getElementById( 'frm_form_' + id + '_container' ) );
2425 1368 if ( scrollObj.length < 1 ) {
2426 1369 return;
2427 1370 }
2428 1371 } 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();
1372 + scrollObj = jQuery( object ).find( '#frm_field_' + id + '_container' );
2432 1373 } else {
2433 1374 scrollObj = id;
2434 1375 }
2435 1376
@@ -2439,12 +1380,12 @@
2439 1380 return;
2440 1381 }
2441 1382 newPos = newPos - frm_js.offset;
2442 1383
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 );
1384 + m = jQuery( 'html' ).css( 'margin-top' );
1385 + b = jQuery( 'body' ).css( 'margin-top' );
1386 + if ( m || b ) {
1387 + newPos = newPos - parseInt( m ) - parseInt( b );
2447 1388 }
2448 1389
2449 1390 if ( newPos && window.innerHeight ) {
2450 1391 screenTop = document.documentElement.scrollTop || document.body.scrollTop;
@@ -2451,12 +1392,12 @@
2451 1392 screenBottom = screenTop + window.innerHeight;
2452 1393
2453 1394 if ( newPos > screenBottom || newPos < screenTop ) {
2454 1395 // Not in view
2455 - if ( animate === undefined ) {
2456 - document.documentElement.scrollTop = newPos;
1396 + if ( typeof animate === 'undefined' ) {
1397 + jQuery( window ).scrollTop( newPos );
2457 1398 } else {
2458 - animateScroll( screenTop, newPos, 500 );
1399 + jQuery( 'html,body' ).animate({ scrollTop: newPos }, 500 );
2459 1400 }
2460 1401 return false;
2461 1402 }
2462 1403 }
@@ -2461,13 +1402,13 @@
2461 1402 }
2462 1403 }
2463 1404 },
2464 1405
2465 - fieldValueChanged( e ) {
1406 + fieldValueChanged: function( e ) {
2466 1407 /*jshint validthis:true */
2467 1408
2468 - const fieldId = frmFrontForm.getFieldId( this, false );
2469 - if ( ! fieldId ) {
1409 + var fieldId = frmFrontForm.getFieldId( this, false );
1410 + if ( ! fieldId || typeof fieldId === 'undefined' ) {
2470 1411 return;
2471 1412 }
2472 1413
2473 1414 if ( e.frmTriggered && e.frmTriggered == fieldId ) {
@@ -2473,9 +1414,9 @@
2473 1414 if ( e.frmTriggered && e.frmTriggered == fieldId ) {
2474 1415 return;
2475 1416 }
2476 1417
2477 - jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ] );
1418 + jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]);
2478 1419
2479 1420 if ( e.selfTriggered !== true ) {
2480 1421 maybeValidateChange( this );
2481 1422 }
@@ -2480,10 +1421,56 @@
2480 1421 maybeValidateChange( this );
2481 1422 }
2482 1423 },
2483 1424
2484 - escapeHtml( text ) {
2485 - console.warn( 'DEPRECATED: function frmFrontForm.escapeHtml in v6.17' );
1425 + savingDraft: function( object ) {
1426 + console.warn( 'DEPRECATED: function frmFrontForm.savingDraft in v3.0 use frmProForm.savingDraft' );
1427 + if ( typeof frmProForm !== 'undefined' ) {
1428 + return frmProForm.savingDraft( object );
1429 + }
1430 + },
1431 +
1432 + goingToPreviousPage: function( object ) {
1433 + console.warn( 'DEPRECATED: function frmFrontForm.goingToPreviousPage in v3.0 use frmProForm.goingToPreviousPage' );
1434 + if ( typeof frmProForm !== 'undefined' ) {
1435 + return frmProForm.goingToPreviousPage( object );
1436 + }
1437 + },
1438 +
1439 + hideOrShowFields: function() {
1440 + console.warn( 'DEPRECATED: function frmFrontForm.hideOrShowFields in v3.0 use frmProForm.hideOrShowFields' );
1441 + if ( typeof frmProForm !== 'undefined' ) {
1442 + frmProForm.hideOrShowFields();
1443 + }
1444 + },
1445 +
1446 + hidePreviouslyHiddenFields: function() {
1447 + console.warn( 'DEPRECATED: function frmFrontForm.hidePreviouslyHiddenFields in v3.0 use frmProForm.hidePreviouslyHiddenFields' );
1448 + if ( typeof frmProForm !== 'undefined' ) {
1449 + frmProForm.hidePreviouslyHiddenFields();
1450 + }
1451 + },
1452 +
1453 + checkDependentDynamicFields: function( ids ) {
1454 + console.warn( 'DEPRECATED: function frmFrontForm.checkDependentDynamicFields in v3.0 use frmProForm.checkDependentDynamicFields' );
1455 + if ( typeof frmProForm !== 'undefined' ) {
1456 + frmProForm.checkDependentDynamicFields( ids );
1457 + }
1458 + },
1459 +
1460 + checkDependentLookupFields: function( ids ) {
1461 + console.warn( 'DEPRECATED: function frmFrontForm.checkDependentLookupFields in v3.0 use frmProForm.checkDependentLookupFields' );
1462 + if ( typeof frmProForm !== 'undefined' ) {
1463 + frmProForm.checkDependentLookupFields( ids );
1464 + }
1465 + },
1466 +
1467 + loadGoogle: function() {
1468 + console.warn( 'DEPRECATED: function frmFrontForm.loadGoogle in v3.0 use frmProForm.loadGoogle' );
1469 + frmProForm.loadGoogle();
1470 + },
1471 +
1472 + escapeHtml: function( text ) {
2486 1473 return text
2487 1474 .replace( /&/g, '&amp;' )
2488 1475 .replace( /</g, '&lt;' )
2489 1476 .replace( />/g, '&gt;' )
@@ -2490,82 +1477,97 @@
2490 1477 .replace( /"/g, '&quot;' )
2491 1478 .replace( /'/g, '&#039;' );
2492 1479 },
2493 1480
2494 - triggerCustomEvent,
2495 - documentOn
1481 + invisible: function( classes ) {
1482 + jQuery( classes ).css( 'visibility', 'hidden' );
1483 + },
1484 +
1485 + visible: function( classes ) {
1486 + jQuery( classes ).css( 'visibility', 'visible' );
1487 + }
2496 1488 };
2497 1489 }
1490 +frmFrontForm = frmFrontFormJS();
2498 1491
2499 -window.frmFrontForm = frmFrontFormJS();
2500 -
2501 1492 jQuery( document ).ready( function() {
2502 1493 frmFrontForm.init();
2503 -} );
1494 +});
2504 1495
2505 1496 function frmRecaptcha() {
2506 - frmCaptcha( '.frm-g-recaptcha' );
1497 + var c, cl,
1498 + captchas = jQuery( '.frm-g-recaptcha' );
1499 + for ( c = 0, cl = captchas.length; c < cl; c++ ) {
1500 + frmFrontForm.renderRecaptcha( captchas[c]);
1501 + }
2507 1502 }
2508 1503
2509 -function frmHcaptcha() {
2510 - frmCaptcha( '.h-captcha' );
1504 +function frmAfterRecaptcha( token ) {
1505 + frmFrontForm.afterSingleRecaptcha( token );
2511 1506 }
2512 1507
2513 -function frmTurnstile() {
2514 - frmCaptcha( '.frm-cf-turnstile' );
1508 +function frmUpdateField( entryId, fieldId, value, message, num ) {
1509 + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' );
1510 + jQuery.ajax({
1511 + type: 'POST',
1512 + url: frm_js.ajax_url,
1513 + data: {
1514 + action: 'frm_entries_update_field_ajax',
1515 + entry_id: entryId,
1516 + field_id: fieldId,
1517 + value: value,
1518 + nonce: frm_js.nonce
1519 + },
1520 + success: function() {
1521 + if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) {
1522 + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' );
1523 + } else {
1524 + jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).replaceWith( message );
1525 + }
1526 + }
1527 + });
2515 1528 }
2516 1529
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 - } );
1530 +function frmDeleteEntry( entryId, prefix ) {
1531 + console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' );
1532 + jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' );
1533 + jQuery.ajax({
1534 + type: 'POST',
1535 + url: frm_js.ajax_url,
1536 + data: {
1537 + action: 'frm_entries_destroy',
1538 + entry: entryId,
1539 + nonce: frm_js.nonce
1540 + },
1541 + success: function( html ) {
1542 + if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) {
1543 + jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' );
1544 + } else {
1545 + jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( html );
1546 + }
2529 1547 }
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 - }
1548 + });
2557 1549 }
2558 1550
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;
1551 +function frmOnSubmit( e ) {
1552 + console.warn( 'DEPRECATED: function frmOnSubmit in v2.0 use frmFrontForm.submitForm' );
1553 + frmFrontForm.submitForm( e, this );
2567 1554 }
2568 1555
2569 -function frmAfterRecaptcha( token ) {
2570 - frmFrontForm.afterSingleRecaptcha( token );
1556 +function frm_resend_email( entryId, formId ) { // eslint-disable-line camelcase
1557 + var $link = jQuery( document.getElementById( 'frm_resend_email' ) );
1558 + console.warn( 'DEPRECATED: function frm_resend_email in v2.0' );
1559 + $link.append( '<span class="spinner" style="display:inline"></span>' );
1560 + jQuery.ajax({
1561 + type: 'POST',
1562 + url: frm_js.ajax_url,
1563 + data: {
1564 + action: 'frm_entries_send_email',
1565 + entry_id: entryId,
1566 + form_id: formId,
1567 + nonce: frm_js.nonce
1568 + },
1569 + success: function( msg ) {
1570 + $link.replaceWith( msg );
1571 + }
1572 + });
2571 1573 }