0

hoping someone can help me solve this problem, thanks a lot for providing the solution

i recently had a problem with my library called my_form_validation on codeigniter version 3. i don't know why it can enter validation true even though it was wrong in function photo check

I have done several options but none of the results I want. my example already used the callback it's the same

example code controller

public function validation_photo()
    {
        // load custom library Validation
        $this->my_form_validation->config_photo();
        $this->my_form_validation->photo_checker($_FILES['photo']);

        // Conditional validation form
        if ($this->form_validation->run() == FALSE) {
            // does not pass validation
            $data['Title'] = 'Profile';
            $data['Content'] = 'management/V_Profile';
            $this->load->view('dinamis/Layout', $data);
        } else {
            // passed validation
            var_dump('passed');
        }
    }

the code above is my loading from my_form_validation library which works for configuring and validating the upload format

example code my_form_validation (config_photo)

function config_photo()
    {
        $ci = get_instance();
        $config = array(
            array(
                'field' => 'photo',
                'label' => 'photo',
                'rules' => 'photo_checker',

            ),
        );

        $ci->form_validation->set_rules($config);
    }

the code above is to set the rules to be used, I use photo_checker

example code my_form_validation (photo_checker)

function photo_checker($photo)
    {
        $ci = get_instance();
        $allowed_mime_type_arr = array('image/jpeg', 'image/png', 'image/x-png', 'image/jpg');
        $mime = $photo['type'];
        if (in_array($mime, $allowed_mime_type_arr)) {
            return TRUE;
        } else {
            $ci->form_validation->set_message('photo_checker', 'Please select a supported format (jpeg,png,jpg).');
            return FALSE;
        }
    }

The above code is for validating if it doesn't match the desired format then it returns false with the message set

very very thank you very much for helping me.

I hope this issue gets resolved well in this forum, I'm sure there are really great people here

0 Answers0