Welcome Guest, Not a member yet? Register   Sign In
validation not working
#1

Hi, I'm a newbie and I want to ask you something about validation.
I just created some rules for form validation.

This is my Controller : 
Code:
public function create()
    {
        if (!$this->validate([
            'name' => [
                'rules'  => 'required',
                'errors' => [
                    'required' => 'Field Name is required.',
                ]
            ]
        ])) {
            $validation = $this->validation;
            session()->setFlashdata('fail', 'something wrong, Check your form input!');
            return redirect()->back()->withInput()->with('validation', $validation);
        } else {
            dd("OK");
        }
    }

This is my View : 
Code:
<form action="/Home/create" method="post" enctype="multipart/form-data">
   <?= csrf_field(); ?>
   <div class="mb-3">
       <label for="name" class="form-label">Nama</label>
       <input type="text" class="form-control <?= ($validation->hasError('name')) ? 'is-invalid' : ''; ?>" id="name" name="name" value="<?= old('name'); ?>" autofocus autocomplete="off">
       <div class="invalid-feedback">
           <?= $validation->getError('name'); ?>
       </div>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>


But when I tried to submit the form with the empty field and I dd($validation->getError('name')) the return is empty error data.

My PHP Version : 8.2.12
My CodeIgniter Version : 4.5.5

Please Help Me, Master.
Reply


Messages In This Thread
validation not working - by Anharr - 09-16-2024, 12:04 AM
RE: validation not working - by wdeda - 09-16-2024, 04:47 AM
RE: validation not working - by Anharr - 09-16-2024, 07:23 AM
RE: validation not working - by kenjis - 09-16-2024, 06:57 PM
RE: validation not working - by kenjis - 09-16-2024, 06:47 PM
RE: validation not working - by kenjis - 09-16-2024, 06:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB