1function submeterForm() { 2 const $ = jQuery; 3 var form = $('form#form-opine'); 4 5 if (form[0].checkValidity()) { 6 var data = new FormData(); 7 const btnEnviar = form.find('#btn-enviar'); 8 btnEnviar.prop('disabled', true); 9 const formParams = form.serializeArray(); 10 11 $.each(formParams, function (i, val) { 12 data.append(val.name, val.value); 13 }); 14 15 data.append("optin", "Aceito"); 16 data.append("categoria", "formulario-news-letter"); 17 data.append("telefone", "(61)99999-9999"); 18 19 // Envia os dados via AJAX 20 $.ajax({ 21 method: "POST", 22 url: "/wp-content/themes/px-poupex/assets/php/leadsServiceAjax-postLeads.php", 23 data: data, 24 contentType: false, 25 processData: false, 26 cache: false 27 }) 28 .done(response => { 29 try { 30 const retorno = JSON.parse(response); 31 32 if (retorno.errors) { 33 Swal.fire({ 34 title: 'Erro', 35 text: retorno.errors[0], 36 icon: 'error', 37 confirmButtonText: 'Ok', 38 customClass: { 39 confirmButton: 'btn-blue-500', 40 cancelButton: 'btn-red' 41 } 42 }); 43 } else { 44 45 window.dataLayer.push({ event: 'formSubmit' }); 46 47 Swal.fire({ 48 title: 'Sucesso', 49 text: 'Formulário enviado com sucesso.', 50 icon: 'success', 51 confirmButtonText: 'Ok', 52 customClass: { 53 confirmButton: 'btn-blue-500', 54 cancelButton: 'btn-red' 55 } 56 }).then((result) => { 57 if (result.isConfirmed) { 58 form[0].reset(); 59 } 60 }); 61 } 62 } catch (error) { 63 console.error("Erro ao processar a resposta:", error); 64 } 65 66 btnEnviar.prop('disabled', false); 67 }) 68 .fail(() => { 69 Swal.fire({ 70 title: 'Erro', 71 text: 'Ops... Houve um problema, tente novamente.', 72 icon: 'error', 73 confirmButtonText: 'Ok', 74 customClass: { 75 confirmButton: 'btn-blue-500', 76 cancelButton: 'btn-red' 77 } 78 }); 79 80 console.error("Erro na requisição AJAX"); 81 btnEnviar.prop('disabled', false); 82 }); 83 } 84} 85function submeterForm_Old(event) { 86 event.preventDefault(); 87 88 var form = jQuery('form#form-opine'); 89 90 if (!form.length) { 91 console.error('Formulário #form-opine não encontrado'); 92 return; 93 } 94 95 // Validação HTML5 96 if (!form[0].checkValidity()) { 97 form[0].reportValidity(); 98 return; 99 } 100 101 var data = new FormData(form[0]); 102 103 jQuery('form#form-opine #btn-enviar') 104 .attr('disabled', true) 105 .text('Enviando...'); 106
107 jQuery.ajax({ 108 method: "POST", 109 url: "/wp-content/themes/px-poupex/assets/php/salvaDadosNewsLetter.php", 110 data: data, 111 contentType: false, 112 processData: false, 113 cache: false 114 }) 115 .done(function (data) { 116 // data pode vir como string ou já como objeto 117 var retorno = (typeof data === 'string') ? jQuery.parseJSON(data) : data; 118 119 if (retorno.errors) { 120 cuteAlert({ 121 type: 'error', 122 title: 'Erro', 123 message: retorno.errors[0], 124 buttonText: 'Ok' 125 }); 126 } else if (retorno.code) { 127 cuteAlert({ 128 type: 'error', 129 title: 'Erro', 130 message: retorno.description || 'Erro ao processar a requisição.', 131 buttonText: 'Ok' 132 }); 133 } else { 134 cuteAlert({ 135 type: 'success', 136 title: 'Sucesso', 137 message: retorno.message || 'Formulário enviado com sucesso.', 138 buttonText: 'Ok' 139 }); 140 141 // limpa o formulário após sucesso 142 form[0].reset(); 143 } 144 145 jQuery('form#form-opine #btn-enviar') 146 .attr('disabled', false) 147 .text('Assinar newsletter'); 148 }) 149 .fail(function (error) { 150 cuteAlert({ 151 type: 'error', 152 title: 'Erro', 153 message: 'Ops... Houve um problema, tente novamente.', 154 buttonText: 'Ok' 155 }); 156 157 console.error("error", error); 158 jQuery('form#form-opine #btn-enviar') 159 .attr('disabled', false) 160 .text('Assinar newsletter'); 161 }); 162}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.