F
F
filippokk2015-12-16 21:48:14
PHP
filippokk, 2015-12-16 21:48:14

Ajax contact form?

Good evening, there is a feedback form and there is a handler for it:

function submitForm(){
    // Переменные с данными из формы
    var name = $("#name").val();
    var email = $("#email").val();
    var message = $("#message").val();
 
    $.ajax({
        type: "POST",
        url: "php/form-process.php",
        data: "name="+ name + "&email="+ email + "&message="+ message,
        success : function(text){
            if(text == "success"){
                formSuccess();
            }
        }
    });
}
function  formSuccess(){
    $( "#msgSubmit").removeClass( "hidden");
    $( "#contactForm").find('input[type=text], textarea').val('');
}


If there is one form on the page, then everything works fine, when there is more than 1 form on the page, then it does not work, and in order for everything to work, you need to duplicate this code and change the id, please tell me how to implement this, no matter the number of forms on the page did this code handle them all without duplication with another id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-12-16
@webinar

Why multiple contact forms on one page?
But you can pass the form id to the submitForm function, and instead of $("#input id").val() use #input id-input id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question