• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

#2
I think you need to specify images.0 for all the images fields.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.