lonnieezell / myth-auth

One-stop Auth package for CodeIgniter 4
MIT License
632 stars 207 forks source link

Help : Validation input CodeIgniter 4 didn't work #585

Closed endyarfian closed 1 year ago

endyarfian commented 1 year ago

I got some issues right after installing myth/auth, my validation input didn't work after all, i can't get the error message from them. It worked fine before I used myth/auth and after I delete myth/auth. here is some example of my validation input :

` public function savertka() { if (!$this->validate([ 'kodertka' => [ 'rules' => 'required|is_unique[rttahunankegalokasi.kode_rencana_tahunan_alokasi]', 'errors' => [ 'required' => 'data harus diisi.', 'is_unique' => 'data sudah ada di database.' ] ], 'kodertk' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'berlaku' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'berakhir' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'kodecupet' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'kodehwd' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'satuan' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'volume' => [ 'rules' => 'required|decimal', 'errors' => [ 'required' => 'Data harus diisi.', 'decimal' => 'Data harus berupa angka.', ] ], 'des' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], 'pj' => [ 'rules' => 'required', 'errors' => [ 'required' => 'Data harus diisi.', ] ], ])) { $validation = \Config\Services::validation(); return redirect()->to('database/alokasi-realisasi')->withInput()->with('validation', $validation); } $this->RTKAlokasiModel->save([ 'kode_rencana_tahunan_alokasi' => $this->request->getVar('kodertka'), 'kode_rencana_tahunan_kegiatan' => $this->request->getVar('kodertk'), 'tanggal_berlaku' => $this->request->getVar('berlaku'), 'tanggal_berakhir' => $this->request->getVar('berakhir'), 'kode_cucu_petak' => $this->request->getVar('kodecupet'), 'kode_hwd' => $this->request->getVar('kodehwd'), 'satuan' => $this->request->getVar('satuan'), 'volume' => $this->request->getVar('volume'), 'deskripsi' => $this->request->getVar('des'), 'pj' => $this->request->getVar('pj'), ]);

    session()->setFlashdata(['info' => 'success', 'judul' => 'MANTAPPP!👍', 'pesan' => 'Data Berhasil Ditambahkan.']);
    return redirect()->to('database/alokasi-realisasi');
}

`

manageruz commented 1 year ago

Hi @endyarfian. First of all please reformat your code example like php code, so we can have a look to it. And show me full code of your controller, model and view file where you getting problem.

manageruz commented 1 year ago

Your example is unreadable. Give me your full real code where you have a problem, not some part.

manageruz commented 1 year ago

And if you need help or have a question then the right place is discussions.

manageruz commented 1 year ago

Please check this example and modify yours according to this:


<?php

namespace App\Controllers;

class UserController extends BaseController
{
    public function updateUser(int $userID)
    {
        if (! $this->validate([
            'email' => "required|is_unique[users.email,id,{$userID}]",
            'name'  => 'required|alpha_numeric_spaces',
        ])) {
            return view('users/update', [
               // if validation fails, we send validation errors to the view file to show to the user
                'errors' => $this->validator->getErrors(),
            ]);
        }

        // do something here if successful...
    }
}
endyarfian commented 1 year ago

And if you need help or have a question then the right place is discussions.

thanks for your responses, I think I should move this issue to discussion.

manageruz commented 1 year ago

So closing as solved. Feel free to continue on discussions.