Welcome Guest, Not a member yet? Register   Sign In
Validation uploaded files not work with redirect back?
#1

I've tried to validate the input of a form then use redirect()->back() but the validator doesn't work validating the upload file. I've checked with getErrors() function but its empty.
How to solve that issue? I really appreciate for your help and response.

PHP Code:
public function index($id_customer)
    {
        $session session();
        $data['customer'] = $this->CustomerModel->getCustomerById($id_customer);
        $data['validation'] = \Config\Services::validation();

        return view('form'$data);
    }

public function 
add($id_customer)
    {
        $session session();

        $rules = [
             // I don't know why if I comment 'images' rule the validation goes well
            'images' => [
                'label' => 'Images',
                'rules' => 'uploaded[images.0]|max_size[images,4096]|is_image[images]|mime_in[images,image/gif,image/jpeg,image/png]',
                'errors' => [
                    'uploaded' => '{field} field is required',
                    'is_image' => 'Uploaded files are not Image files.',
                    'max_size' => 'Allowed maximum size is 4MB',
                    'mime_in' => 'The Image type is not allowed. Allowed types : gif, jpeg, png'
                ],
            ],
            'notes' => [
                'label' => 'Notes',
                'rules' => 'required',
                'errors' => [
                    'required' => '{field} field is required'
                ]
            ],
        ];

        if (!$this->validate($rules)) {
            // Validator with rules
            $validation = \Config\Services::validation();
            return redirect()->back()->withInput()->with('validation'$validation); //redirect to Index function
        
    
Reply


Messages In This Thread
Validation uploaded files not work with redirect back? - by mrardiyansyah - 11-30-2020, 10:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB