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