Hi, i'm setting up a couple of forms on the admin section of a CMS i'm developing. I want to use (unobtrusive) modal forms using JQuery, but I'm not sure how to return error messages/feedback from the server and display them within the modal window.
So this is where i've got to. On my main page (containing all the JS), I am loading a form from an external page and this is being displayed in the modal window. So the external code which is being loaded in the modal window contains an html form as well as the php script for processing the form and sending a JSON response based on validation/success etc. I want to be able to access the response from the php script and display it in the modal window, however, at the moment all that is happening is i click submit and form inside the modal window is duplicated.
Here is the code which is causing the problem - hope someone can help!
$(document).ready(function(){
$("table")
.tablesorter({widthFixed: true})
.tablesorterPager({container: $("#pager")});
$("a.user_admin").colorbox({transition:"elastic"}, function() { // onload...do
$('#edit_user').submit(function() {
var inputs = [];
$(':input', this).each(function() {
inputs.push(this.name + '=' + escape(this.value));
})
jQuery.ajax({
data: inputs.join('&'),
url: this.action,
timeout: 2000,
error: function() {
console.log("Failed to submit");
},
success: function(r) {
$("#message").before(r);
}
})
return false;
})
})
});