Hi Amit Shah,
Thanks for taking the time to consider this.
Firebug shows that the POST request shows that the field contains the word test
The database is update with the field even though the callback should return false if the field = 'test'
The page goes back to the list showing the update and a success message.
This is what firebug says:
Partsmultipart/form-data
test1
ghjkghjk
test2
test
Source
-----------------------------16723893271491002339521612960 Content-Disposition: form-data; name="test1" ghjkghjk -----------------------------16723893271491002339521612960 Content-Disposition: form-data; name="test2" test -----------------------------16723893271491002339521612960--
with response
<textarea>{"success":true}</textarea>
and
<textarea>{"success":true,"insert_primary_key":true,"success_message":"<p>Your data has been successfully updated. <a href='http:\/\....../bic\/admin\/tests'>Go back to list<\/a><\/p>","success_list_url":"http:\/\....../bic\/admin\/tests\/success\/2"}</textarea>
That all looks correct as far as the client side goes, but...
Actually in the function it should dump something and stop at the die and not complete the update. That's what makes me think that it is not calling the callback function at all, but just update/inserts into the database.
There are no entries in the httpd error_log
and the httpd access_log shows everything as a success
192.168.20.6 - - [20/Aug/2013:16:19:12 +0100] "GET /90_developments/bic/admin/tests/edit/2 HTTP/1.1" 200 4895 "http:/.../90_developments/bic/admin/tests/success/2" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0"
192.168.20.6 - - [20/Aug/2013:16:19:27 +0100] "POST /90_developments/bic/admin/tests/update_validation/2 HTTP/1.1" 200 37 "
http://.../90_developments/bic/admin/tests/edit/2" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0"
This sort of issue is usually a syntax error or the like but I cannot see anything like that. I think I have followed the docs to the letter
This is the complete controller as tested above
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Tests extends CI_Controller {
function __construct()
{
parent::__construct();
/* Standard Libraries of codeigniter are required */
$this->load->database();
$this->load->helper('url');
$this->load->helper('text');
$this->load->helper('inflector');
$this->load->library('form_validation');
/* ------------------ */
$this->load->library('grocery_CRUD');
}
public function test_list()
{
$crud = new grocery_CRUD();
$crud->set_subject('Test');
$crud->set_table('tests');
$crud->fields('test1','test2');
$crud->set_rules('test2','callback_test_check');
$output = $crud->render();
$this->_test_output($output);
}
function test_check($str)
{
var_dump($str);
die;
if ($str == 'test')
{
$this->form_validation->set_message('Test 2', 'Test 2 must not be test');
return false;
}
else
{
return true;
}
}
function _test_output($output = null)
{
$this->load->view('admin/admin_template.php',$output);
}
}
/* End of file tests.php */
/* Location: ./application/controllers/admin/tests.php */
The database table is just this:
mysql> desc tests;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| test1 | varchar(16) | NO | | NULL | |
| test2 | varchar(16) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
It's all very simple but I don't know what to try next