APIs & Integrations

abiam
Member

Stop information from being sent

Hi! I'm trying to customize my form with some tweaks, and the last one I need to work is that, when the contact meets one of the three validation conditionals, the form needs to be stopped from sending the infos to hubspot.

 

The code I already have is this one. I'm using wordpress + elementor combo, and the form show up as a popup when clicking on a button on the page.

 

Any help is appreciated!!

 

<div id="formTarget"></div>
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js"></script>
<script>
hbspt.forms.create({
region: "na1",
portalId: "39782198",
formId: "8ff9e15d-62da-428a-bc2f-ababa33907e7",
target: "#formTarget",
onFormReady: function(jQueryform) {
// Adicione um ouvinte de evento de envio do formulário
jQueryform[0].addEventListener("submit", function(event) {
var qualificacao = jQueryform.find('select[name="aposentado_ou_pensionista_"]').val();
var diagnostico = jQueryform.find('select[name="diagnostico"]').val();
var salarioBruto = jQueryform.find('select[name="salario_bruto_de_beneficio"]').val();

console.log(qualificacao);

if (qualificacao == "Nenhuma das opções" || diagnostico == "Outra Enfermidade" || salarioBruto != "Até R$3.500,00") {
// Impede o envio padrão do formulário
event.preventDefault();

// Desativa e oculta o botão de enviar
jQueryform.find('[type="submit"]').prop('disabled', true).hide();

// Adiciona um botão de fechar
var closeButton = jQuery('<button class="fecha-janela">Fechar</button>');
closeButton.click(function() {
// Fecha a popup
jQuery('#elementor-popup-modal-466').hide();
});
jQueryform.append(closeButton);

// Exibe um alerta personalizado
alert("Infelizmente você não cumpre os requisitos para receber o benefício.");
} else {
// Lead qualificado, redireciona para a página de obrigado
window.location.href = "https://google.com";
}
});
}
});
</script>

0 Upvotes
1 Reply 1
Jaycee_Lewis
Community Manager
Community Manager

Stop information from being sent

Hey, @abiam 👋 Thanks for the interesting question. Did you get any closer to finding the root issue? 

 

If not, have you tried:

  • Have you tried using console.log() statements to print the values of qualificacao, diagnostico, and salarioBruto? To verify the values checked are what you expect to see.
    console.log('Qualificação:', qualificacao);
    console.log('Diagnóstico:', diagnostico);
    console.log('Salário Bruto:', salarioBruto);
    ​
  • Have you tried wrapping this inside a window.onload function or jQuery’s $(document).ready() function? To make sure everything is loaded before your script runs.

Thank you for the additional details! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes