Answer the question
In order to leave comments, you need to log in
Yandex Metrica - how to set up a goal for submitting a form?
Hello!
There is a form:
<form method="post" action="./handlers/contact-square.php" id="first-form" onsubmit="yaCounter50578219.reachGoal('first-form'); return true;">
yaCounter50578219.reachGoal('first-form'); return true;
into the form handler at the moment when the actual submission occurs. The question is how to do it? Handler code:$('#first-form').validate({
debug: false,
onfocusout: true,
onKeyUp: true,
rules: {
chosen_brand: {
required: true
},
number: {
required: true,
regexp: /^\+\d{1}\(\d{3}\)\d{3}-\d{2}-\d{2}$/
}
},
messages: {
chosen_brand: {
required: "Введите сообщение"
},
number: {
required: "Введите телефон",
regexp: "Некорректно"
}
},
wrapper: "div",
errorPlacement: function(error, element) {
if(element.siblings('.errors_block').length>0){
element.siblings('.errors_block').html(error[0].textContent);
}else{
element.after('<span class="errors_block">'+error[0].textContent+'</span>');
}
},
success: function(element) {
if(element.siblings('.errors_block').length>0){
element.siblings('.errors_block').remove();
}
}
});
Answer the question
In order to leave comments, you need to log in
use ajax . for successful sending, hang up the goal.
$.ajax({
url: url,
type: 'POST',
data: data,
success: function (data) {
yaCounter50578219.reachGoal('first-form');
},
error: function (data) {
console.log('Ошибка: ' + data);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question