Welcome Guest, Not a member yet? Register   Sign In
Validation Bug??
#1

Hi
There seems to be a problem with form validation (Ci4). IS THIS A BUG ????

I have writtem my validation rules to config/validation.php as per the documentation. The problem is two-fold. 1) Assuming the "Rules for File Upload" interrogate the file header the following do not seem to work at all ( max_size, mime_in, ext_in),  and, 2) the configured error message configured for the rule is not return when the validation fails. Please see the following:

Script
PHP Code:
$file $this->request->getFile('image');  //file upload.jpg  mime = image/jpg, size = 35475  extension = jpg
$id $this->request->getPost('id'); // value = 7

$validation->reset();

$validation_array=array('file'=>$file'id'=>$id);

$validation->run($validation_array'image_upload');
                
$validation_errors=$validation->getErrors(); 

Validation
PHP Code:
public $image_upload = [
        
'file' => [
            
'rules' => 'mime_in[file,image/jpg,image/jpeg,image/gif,image/png]',
            
'errors' => [
                
'mime_in' => 'Invalid Image File. Only jpg, jpeg, gif or png allowed'
            
],
        ],
        
        
'id' => [
            
'rules'  => 'required',
            
'errors' => [
                
'required' => 'User Not Defined.'
            
]
        ]
    ]; 

The above returns {"file":"file does not have a valid mime type.","id":"The id field is required"}
1) There should NOT be errors
2) If there is errors the above should return  {"file":"Invalid Image File. Only jpg, jpeg, gif or png allowed","id":"User Not Defined."}

Now if I run the following validation (to ensure the validator is configured properly)..

PHP Code:
$validation_array=array('file'=>$file'id'=>'7'); 

The above returns {"file":"file does not have a valid mime type."}
If there is errors the above should return  {"file":"Invalid Image File. Only jpg, jpeg, gif or png allowed",}

IS THIS A BUG ??????

Many thanks (in advance).
Reply


Messages In This Thread
Validation Bug?? - by 68thorby68 - 05-15-2020, 03:48 AM
RE: Validation Bug?? - by kick - 05-15-2020, 12:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB