Welcome Guest, Not a member yet? Register   Sign In
Issue with Model Validation
#1

(This post was last modified: 05-07-2024, 07:18 PM by osawayn.)

When using the Model validation features in CodeIgniter 4, I'm finding that some of the validation rules aren't working as expected. For instance, the "required" rule doesn't seem to be triggering the expected validation error when the field is left empty. Additionally, the "valid_email" rule also doesn't appear to be validating the email format correctly.

Steps Taken:
1. I've verified that the validation rules are correctly defined in the model.
2. I've confirmed that the fields being validated are present in the form submission data.
3. I've reviewed the official documentation and compared my implementation with the examples provided.

Code:
// Sample validation rules in the model
protected $validationRules = [
    'email' => 'required|valid_email',
    'username' => 'required|min_length[5]'
];
I'd appreciate any guidance or advice on how to troubleshoot and resolve this issue. Has anyone else encountered similar problems with model validation in CodeIgniter 4? Any pointers on best practices or potential pitfalls to watch out for would be immensely helpful.

Thanks in advance!
Reply
#2

Validation should work with your case unless $skipValidation is true.
https://codeigniter4.github.io/CodeIgnit...validation

But I personally recommend not using validation in model because of its complexity.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB