Is There A Way To Send Data From Diffrent Forms At The Same Time With Only 1 Submit Button?
Solution 1:
If you're using jQuery...
First, give your forms and submit button some IDs (I used #form1, #form2, and #submit). Then...
Edit: Here's a non-AJAX solution that takes advantage of the fact that the forms post to the same URL.
When the submit button is clicked, move/append the text input $(input[name=baslik])
to the second form and then submit it. This solution doesn't need the jQuery Form plugin and doesn't use AJAX:
$("#form2").submit(function() {
$(input[name=baslik]).appendTo($(this));
});
Original, AJAX solution:
If you want AJAX, you can use the jQuery Form Plugin.
$(document).ready(function() {
$('#form1, #form2').ajaxForm(function() {
// optionally do stuff here after forms submitted
});
$('#submit').click(function() {
$('#form1, #form2').ajaxSubmit();
returnfalse;
});
});
You can't use jQuery's $(form).serialize()
because it does not work on file fields. This solution also assumes you want to use AJAX.
Solution 2:
One option would be forcing javascript being used: launch a javascript handler that collects the values, submits a ajax request, or even writes a form and submits it.
Jquery can easily be used to to loop through all form values.
So something like:
$("#first_form").submit(function() {
//collect all values here
first_form_data = $("#first_form").serialize();
second_form_data = $("#second_form").serialize();
$.ajax({
url: ..,
data: first_form_data + "&" + second_form_data,
success: function(data) {
}
}
//let’s not submit the formreturnfalse;
}
Solution 3:
Yes.
remove the input that submits, and add a link outside every form with the javascript that submits all: (also add an ID to everyform, so you can call them via this javascript)
function submitAll(){
document.forms["IDform1"].submit();
document.forms["IDform2"].submit();
}
EDIT: this doesn't work, the only way is via AJAX, please check @Phil's answer!
Post a Comment for "Is There A Way To Send Data From Diffrent Forms At The Same Time With Only 1 Submit Button?"