Welcome Guest, Not a member yet? Register   Sign In
CI 1.7.0 Form_Validation rules/callback function possible bug
#1

[eluser]i_am_using_ci[/eluser]
Hi,

I Have controller with couple of functions,

Code:
<?php

class Test extends Controller {

    public function __controller() {
    
        parent::__controller();
        
        $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');
            $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;

    }

}

?>

The problem is:

When I set:

Code:
<?php

$rules = array(
    'field' => 'to_delete[]',
    'label' => 'IDs',
    'rules' => 'callback__ids_handler'
);

?>

without checking template_id, everything was working normally, after adding template_id rule (and making $rules multidimensional array) everything came broken, $ids now string, not array, maybe I mistaked somewhere?

I've re-checked 3 times, so please help Smile


Messages In This Thread
CI 1.7.0 Form_Validation rules/callback function possible bug - by El Forum - 02-15-2009, 05:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB