02-16-2009, 01:20 PM
[eluser]i_am_using_ci[/eluser]
The problem is:
When I submit my form I am getting integer from to_delete[] array after $this->form_validation->run(), I've tried to post it as bug, but got an advice to ask here, maybe I made mistake somewhere...
Code:
<?php
class Test extends Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
function delete() {
$rules = array(
array(
'field' => 'to_delete[]',
'label' => 'IDs',
'rules' => 'callback__ids_handler'
),
array(
'field' => 'template_id',
'label' => 'Template ID',
'rules' => 'callback__template_exists'
)
);
$this->form_validation->set_rules($rules);
if($this->form_validation->run()) {
/*
here after validation process I am getting $ids as string, NOT ARRAY AS IT MUST BE!
*/
$ids = $this->input->post('to_delete'); /* $ids COMES HERE AS STRING, WHY??? */
$template_id = $this->input->post('template_id');
...
}
}
function _ids_handler($ids = array()) {
/* ids comes here as string, but why? */
$to_return = array();
if(!empty($ids)) {
$ids = array_map('intval', array_map('trim', $ids));
foreach($ids as $oneID) {
if($id > 0) {
$to_return[] = $id;
}
}
}
return $to_return;
}
function _template_exists($template_id = 0) {
...
}
}
?>
The problem is:
When I submit my form I am getting integer from to_delete[] array after $this->form_validation->run(), I've tried to post it as bug, but got an advice to ask here, maybe I made mistake somewhere...