$(document).ready(function(){ // var containerId = `#coreForm`; var containerId = '#coreForm-free_proof'; var formId = '#coreForm-free_proof'; var html = `
`; var form_group_prefix = '_form_group_for_'; // var $field_prefix = 'form_field_'; var $error_class = 'has-error animated rubberBand'; // var $o = $('#_form_submit'); var tmpSubmitLabel = ''; var progress = null; var progressInterval = 500; var progressTimer = 0; var progressValue = 0; var waitingForResponse = false; var hasUploadableFiles = false; console.log('>>>>>>>>>>>', formId, containerId); if($(formId).length == 0){ console.log(formId,'not found'); if($('#coreForm').length>0){ $('#coreForm').attr('id', formId.replace('#','')); console.log('changed coreForm id to ',formId); containerId = formId; } } else { console.log('form',formId,'found'); } console.log("loaded v3"); $(containerId).hide(); $(containerId).html(html); $('body').append(getModalHtml()); $('body').append(getFormModalHtml()); setTimeout(function(){ hasUploadableFiles = $(`${containerId} form#_form input[type="file"]`).length>0; tmpSubmitLabel = $(`${containerId} #_form_submit`).val(); $(`${containerId} form#_form`).prepend(''); $(`${containerId} #_form_submit`).replaceWith(''); if($(`${containerId} #_form input[name="__uqf__"]`).val().trim()!=''){ handleMultiform(); } $(containerId).show(); },200); function handleMultiform(){ var completeEvent = true; $('body').on('click','.openFormModal',function(){ var id = $(this).data('product'); if($(this).data('handler')){ var handler = `#coreForm-${$(this).data('handler')}`; if(handler != containerId){ completeEvent = false; console.error(handler, containerId); return false; } } if($(this).hasClass("formAutoFillInfo")){ var colors = []; $(`${containerId} #__product_attr_col input, ${containerId} #__product_attr_col select`).each(function(){ if($(this).hasClass('email-field')){ $('#core-form-modal #form_field_email').val($(this).val()); } else if($(this).data('code') == 'Material'){ $('#core-form-modal #form_field_material').val($(this).find('option:selected').text()); } else if($(this).data('code') == 'Color_001'){ if($(this).val()!='None'){ colors.push($(this).find('option:selected').text()); } } else if($(this).data('code') == 'Color_002'){ if($(this).val()!='None'){ colors.push($(this).find('option:selected').text()); } } else if($(this).data('code') == 'Color_003'){ if($(this).val()!='None'){ colors.push($(this).find('option:selected').text()); } } }); $(`#core-form-modal #form_field_colors`).val(colors.join(', ')); } $(`${containerId} #_form input[name="__uqv__"]`).val(id); console.log(id); renderFormModal(`Product: ${id}`, false) }); if(completeEvent){ $(containerId).appendTo('#core-form-modal .modal-body'); } } $('body').on('click',`${containerId} #_form_submit`,function(){ console.log(`${containerId} #_form_submit`); renderModal(`Processing, please wait...
Please wait while your files upload is complete, this can take a few minutes depending on the file size
") } endProgress(); } }, progressInterval); // progressInterval += 10; } function extendProgress(){ // progressInterval += 250; // startProgress(); } function endProgress(){ clearTimeout(progress); progress = null; progressInterval = 100; } function sendData(){ // console.log(containerId); var formData = new FormData($(`${containerId} form#_form`)[0]); var loc = 'https://www.all-stickers.com/forms/quote.js'; if(window.location.hostname == 'localhost'){ loc = 'http://localhost/forms/quote.js'; } // console.log(formData); startProgress(); $(`.formsHandlerSubmitButton`).prop("disable", true); waitingForResponse = true; $.ajax({ // url: 'http://localhost/forms/quote.js', url: loc, type: 'POST', async: true, data: formData, cache: false, contentType: false, processData: false, timeout: 60000, error: function (data) { $(`.formsHandlerSubmitButton`).prop("disable", false); console.error(data); endProgress(); closeModal(); progressTimer = 0; waitingForResponse = false; alert("A server error has occurred"); console.error(data); }, complete: function (data) { $(`.formsHandlerSubmitButton`).prop("disable", false); setTimeout(function(){ if(waitingForResponse){ waitingForResponse = false; endProgress(); closeModal(); progressTimer = 0; } },100); }, success: function (data){ $(`.formsHandlerSubmitButton`).prop("disable", false); waitingForResponse = false; formSuccess(data); }, }); } function formSuccess(data){ endProgress(); if($('#core-form-progress-bar-val').length>0){ // $('#core-form-progress-bar-val').css('animation-duration', '0.0s').removeClass('progress-bar'); $('#core-form-progress-bar-val').css('width',`100%`); } setTimeout(function(){ if(data == ''){ alert("An Unknown error occurred"); } else { data = JSON.parse(data); // console.log(data); if(data.hasOwnProperty("log")){ // console.log(data.log); // console.log(data.log[0].message); } if(data.error){ alert(`** ERROR **\n${data.message}`); if(data.field!=''){ field_error($(`#${data.field}`), ''); } } else { // alert(`${data.title}\n${data.message}`); // alert(`Complete`); } if(data.html!=''){ $(`${containerId} ._messages`).html(data.html); } } closeModal(); $(containerId).get(0).scrollIntoView({behavior: 'smooth'}); },600); } function closeFormModal(){ $('#core-form-modal').modal('hide'); } function renderFormModal(title=''){ $('#core-form-modal .modal-title').html(title); $('#core-form-modal').modal('show'); } function getFormModalHtml(){ if($(`#core-form-modal`).length>0){ return ''; } return `