I have an issue working with codeigniter uri language identifier and form_validation.
The problem is form_validation stops working when I set $config[‘lang_ignore’] to FALSE.
I have tested in a clean codeigniter installation and setup uri language identifier as said in codeigniter’s wiki.
Here’s my controller application/controllers/form_validation_test.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Form_validation_test extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('form_validation_test_view');
}
//Get Ajax POST:
public function getPost()
{
$result = FALSE;
$data = NULL;
$this->load->library('form_validation');
$this->form_validation->set_rules('user','User','required');
$result = $this->form_validation->run();
$response = array(
'result' => $result
);
$this->output->set_content_type('application/json')
->set_output(json_encode($response));
}
}
View application/views/form_validation_view.php:
<script src="http://ci_test.localhost/js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ci_test.localhost/js/ci_test.js"></script>
<form name="formulario" id="formulario" action="http://ci_test.localhost/form_validation_test/getPost">
<input type="text" id="user" name="user" value="">
</form>
<input type="button" id="btnSubmit" value="submit">
<div id="result"></div>
and Javascript file js/ci_test.js:
jQuery(document).ready(function(){
jQuery('#btnSubmit').click(function(){
var postData = jQuery('#formulario').serialize();
var targetUrl = jQuery('#formulario').attr('action');
jQuery.ajax({
url: targetUrl,
data: postData,
type: 'post',
dataType: 'json',
success: function (data, textStatus, jqXHR) {
res = data.result ? 'TRUE':'FALSE';
jQuery('#result').html(res);
}
});
});
});
So as you can see I send post through ajax request, just get the result and place it in div. If you set ‘lang_ignore’ to TRUE it works, but not if you set it to FALSE.
Another behavior I have observed is that when everythig works fine, you see the POST request in firebug but when using lang_ignore as FALSE you can see the POST request and a GET request that remains loading. I have no idea about why this happens but maybe can help someone find the problem.
Any help would be appreciated.
Thanks all for your time.
I found the solution.
If you set lang_ignore parameter to FALSE, the constructor in application/core/MY_lang.php file does one redirection and (correct me if I’m wrong) you lose the POST.
So including language segment goes straight in one single request.
It worked for me, hope can help someone