Answer the question
In order to leave comments, you need to log in
How to make submit work?
Hello!
There is a site on drupal, it is necessary to get data from a filled form using a third-party php script.
I tried using jQuery to collect fields when submitting, but the script does not respond to submission (it finds the form, but submit does not work - apparently, a conflict with some other handler, it works on jsfiddle).
How to implement the plan (and why my event is not hung)?
(function($){
$(document).ready(function(){
console.log('скрипт подключился');
var form1 = $('form#webform-client-form-127');
console.log('form1 - ' + form1.length + ' штук найдено');
//предполагается наличие 2-3 разных форм на странице, нужно отслеживать каждую
//var form2 = $('form#');
var formsArray = [form1];
formsArray.forEach(function(currentForm, index) {
obrabotkaFormi(currentForm);
});
function obrabotkaFormi(currentForm){
console.log('currentForm - ' + currentForm.length + ' штук найдено');
$(document).on('submit', currentForm, function(){
console.log('форма засабмичена');
var data = currentForm.serialize();
$.ajax({
type: 'POST',
url: '/example.php',
data: data
}).done(function() {
console.log(data);
console.log('success');
}).fail(function() {
console.log(data);
console.log('fail');
});
});
}
});
})(jQuery);
Answer the question
In order to leave comments, you need to log in
var formsArray = [form1]
What's this?
It seems to me that you need to use the following construction:
Then all the forms on the page will be in the array at once. If you need to filter out, then you can use some data attribute on the necessary forms and select in the loop only those forms that have this attribute.
Replace with
And further everywhere in the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question