Sending additional information with JQuery remote form validation

后端 未结 1 946
眼角桃花
眼角桃花 2021-01-26 18:40

I\'m trying to remote validate a field by looking at two different fields. The issue is, in all the examples I see on how to do remote validate sending additional data, they\'re

1条回答
  •  悲&欢浪女
    2021-01-26 19:17

    You could assign a unique formId to each of the forms, and whenever the form is submitted, you could submit the formId alongwith the other info from the form in order to identify which form is being submitted?

    For example, in the html code of your form, you could do something like this:

    Form # 1: (with form id as 1)

    Name:
    Address:

    Form # 2: (with form id as 2)

    Name:
    Address:

    In the javascript, something like this:

    function validate(formId)
    {
       var data = {};
       //Example data that is to be submitted for validation:
       data.name = $("#name_" + formId).val();
       data.address = $("#address_" + formId).val();
       //.. and so on
       data.formId = formId;
    
       $.post('http://example.com/confirm.php', data, function(result)
         {
           //process the return of the remote validation here, 
           //found in the variable: result
         }
       );
    }
    

    0 讨论(0)
提交回复
热议问题