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