K
K
keche2017-09-14 16:22:05
JavaScript
keche, 2017-09-14 16:22:05

What is the processing method for each form?

There is a handler that, using AJAX, sends the form data to the mail.
It only processes one form. How to make it process both the second form on the page and the rest - if you add more of them.
The code.

$('form').submit(function() { 
    if ($('form').find("input[name='name']").val() == '' || $('form').find("input[name='email']").val() == '' || $('form').find("input[name='usertext']").val() == '' ) {
      valid = false;
      return valid;
    }
    $.ajax({
      type: "POST",
      url: "php/mail.php",
      data: $(this).serialize()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2017-09-14
@Eridani

Uh. You can, for example, hang an event on the form with a function call

function sendForm(t) {

var url = $(t).attr('action');
var data = new FormData(t);

  $.ajax({
    type: "POST",
    url: url,
    contentType: false,
    processData: false,
    data: data,
    dataType: 'json',
      success: function(data){

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question