1

I've multiple dynamic forms in a single web page like as follows

<form name='login' id='login_1'>
<input type='text' name='username'/>
<input type='password' name='pwd'/>
<input type='submit' name='submit' id='submit_1' value='Login'/>
</form>
<form name='login' id='login_2'>
<input type='text' name='username'/>
<input type='password' name='pwd'/>
<input type='submit' name='submit' id='submit_2' value='Login'/>
</form>
.......
.......

Here id's are dynamic,suppose if user's enters data in second form and submits then I need to send second(only) form data to server without using third party jQuery plugins,here I'm unable to select submit button id properly.

Is it secure process to send data using serializeArray();, especially for login process ?

2 Answers 2

5

One way would be to attach a function $('form').submit() and put your ajax POST to server code there...

$('form').submit(function(){
    var thisForm = $(this);
    alert(thisForm.find("input[type=submit]").attr("id"));

    // perform ajax call here
    // $(ajax). ---

    return false;
});

Here is a demo http://www.bootply.com/61682

Sign up to request clarification or add additional context in comments.

Comments

2

Unless you have form's without files than it is just fine to serialize form inputs.

You can catch the submit event and pass data's using ajax

$("form").submit(function(){
   var action = $(this).attr("action");
   //You Can add an input type hidden to store form id, in case you need it at Server
   $(this).append("<input type='hidden' name='id' value='"+$(this).attr("id")+"'>");
   var data = $(this).serializeArray();
   $.post(action,data,function(data){
     //server response
     console.log(data);
   });
});

1 Comment

what if i have to submit form with file via ajax using a dynamic form, with other input fields details ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.