Form Validation Allowing Empty Strings To Be Stored Instead of Null |
I'm trying to get form validation to work at the model level. I have three fields, id, name and email, and I have them all set to required.
I'm using the CI 4 Entity class, so on an incoming request, I get the JSON, fill my new Entity on creation, and then pass to the model. No matter what I do, for the fields name and email (set to varchar 150 and not NULL in SQL), when I try to insert, name and email are stored as empty strings when I don't include them in my JSON (for instance, if I pass id alone). How can I make it so that if the name and email keys are not passed, the required error is shown? Model: PHP Code: <?php Controller: PHP Code: public function create()
You're missing an end quote on this line:
PHP Code: 'email' => 'required|valid_email|is_unique[users.email] Not sure if that's doing it for you not, but wouldn't help anything.
Sorry, I think I deleted them accidentally when editing my post. Here's the rules and messages again. Still having the problem.
If the JSON doesn't contain name and email, I want it to throw a required error. PHP Code: protected $validationRules = [ |
Welcome Guest, Not a member yet? Register Sign In |