Skip to content

Instantly share code, notes, and snippets.

@luizeof
Last active Oct 6, 2021
Embed
What would you like to do?
Manipulando Eventos de um formulário e enviando para o Mautic
<script>
// Coloque em qualquer parte do código
document.addEventListener('DOMContentLoaded', function () {
// Aqui você coloca o ID do seu formulário que será manipulado
document.getElementById("myForm").onsubmit = function(e) {myFunction(e)};
function myFunction(e) {
// altere aqui a url do seu mautic
var theUrl = 'https://mkt.powertic.com/mtracking.gif';
// Inclua somente os campos que for utilizar
var params = {
email: e.target.elements.namedItem("email").value,
firstname: e.target.elements.namedItem("firstname").value,
phone: e.target.elements.namedItem("phone").value,
// aqui você pode incluir tags
tags: "formA,formContato"
};
var queryString = "?" + Object.keys(params).map(key => key + '=' + params[key]).join('&');
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl + queryString , false ); // false for synchronous request
xmlHttp.send( null );
return true;
}
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment