If you add this to docReady on your main page, it should take care of everything:
$('form').live('submit', function(e){ var successHref = this.action, errorHref = "formError.php"; e.preventDefault(); $('#cboxLoadingGraphic').fadeIn(); $.ajax({ type: "POST", url: "processForm.php", data: {someData: $("#someData").val()}, success: function(response) { if(response=="ok") { console.log("response: "+response); $.colorbox({ open:true, href: successHref }); } else { $.colorbox({ open:true, href: errorHref }); } }, dataType: "html" }); return false; });
This code makes a few assumptions. One of them is that it sends data to processForm.php (as you can see) and awaits a response of βokβ (in plain text, without json) when everything works. If you don't care about the answer or troubleshooting, you can simply remove the if-else
block and open the colorbox with the page set to action
. Anway, you probably want to change it, but it gives you an idea of ββhow this can be done.
source share