[eluser]otherjohn[/eluser]
Hi all,
I have a form loaded via Ajax and submitted via ajax. when the ajax form is loaded, a user can click the save button which using jQuery, submits the form using ajax.
I am getting 2 issues.
1.
When I submit the form, I always get $this->form_validation->run() == FALSE and it never runs to true.
But there is no validation rules setup.
2. if I hit submit again, i get a CSRF error because the token is different but the cookie hasn't changed.
I can't seem to get this simple form to work. There is no validation rules to trip it up! And CSRF token is being sent via ajax
Below is my code:
Code:
My controller Code
function roles($user_id=NULL)
{
if ($this->form_validation->run() == FALSE)
{
..... load form up
}
else
{
echo "Submission worked!";
}
Code:
my ajax code
$('#saveUser').click(function() {
var myurl = $("#userform").attr('action'); // GRAB THE URL FROM THE FORM
$('#displayblock').hide('fast',loadContent);
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
function loadContent() {
$.ajax(
{
type : 'POST',
data: $("#userform").serialize(),
url : myurl,
dataType: 'html',
error: function(xhr, ajaxOptions, thrownError){
$('#displayblock').html(xhr.responseText).show('normal',hideLoader());
},
success : function(data){
$('#displayblock').html(data).show('normal',hideLoader());
}
})
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});