[eluser]nevercraft[/eluser]
I've used facebox quite a bit with CI. Typically I write a simple plugin that handles the form validation from within the facebox.
You can change your form to include onsubmit="return validate_form()"
Then create a javascript function that checks your form fields and returns true or false. If it returns false, the form won't be submitted and you can use jQuery to display the errors. The facebox would stay open until the form submission was valid and returned true.
Some simple code you could use:
Code:
function validate_form() {
var errors = '';
var email_test = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$", "ig");
if ( ! email_test.test($('input[name=email]').val()))
{
errors += "<p>The Email address you've provided is not valid. Please provide a valid email address.</p>";
}
if (errors != '')
{
errors = "<p>Error!</p>" + errors + "<p>Please try again</p>";
// Add a div where you want the errors to show up in your form
$('#somewarningcontainer').html(errors);
return false;
}
else
{
return true;
}
}
If you need to actually have validation happen server side, I'd create a function that used $.post to post to the URL. That would return the HTML to go inside of the facebox. Then you just clear the contents of the facebox body and append the returned HTML:
Code:
function submit_form() { // change your <form> to onsubmit="return submit_form()"
$.post('/controller/method', { form post items }, function(data) {
$('#facebox .content').empty();
$('#facebox .content').html(data);
});
return true;
}
Hope it helps.