phpcodeigniter-2codeigniter-form-helpercodeigniter

codeigniter form validation on array not form submit


i want validate my form input field or you want to say i have an array and i want to validate that array using codeigniter

Example : i have array like :

$array['obj_type']='sample';
$array['obj_id']='44';
$array['user_id']='34566';

and my form validation config as like :

'validatedata' =>  array(
      array(
            'field' => 'obj_type',
            'label' => 'No Type Define here',
            'rules' => 'required'
        ),  
        array(
            'field' => 'obj_id',
            'label' => 'No any item selected here',
            'rules' => 'required|is_natural_no_zero'
        ),
        array(
            'field' => 'user_id',
            'label' => 'No user logged in',
            'rules' => 'required|is_natural_no_zero'
        ),
    ),

and when i use form validate its not validate array

if ($this->form_validation->run('validatedata')) {
} else {
echo validation_errors();
}

its print all error which define on on validatedata config array;


Solution

  • i just use

    $this->form_validation->set_data($array);
    

    then i validate form

    if ($this->form_validation->run('validatedata')) {
    echo "sucess";
    } else {
    echo validation_errors();
    }
    

    now its works fine and good.