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