Welcome Guest, Not a member yet? Register   Sign In
CI Form_validation problem
#1

[eluser]i_am_using_ci[/eluser]
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...


Messages In This Thread
CI Form_validation problem - by El Forum - 02-16-2009, 01:20 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:28 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:32 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:39 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:42 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:47 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:48 PM
CI Form_validation problem - by El Forum - 02-16-2009, 01:51 PM
CI Form_validation problem - by El Forum - 02-16-2009, 02:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB