Welcome Guest, Not a member yet? Register   Sign In
Validation failing on empty fields even when not required
#1

I keep my validation rules in App/Config/Validation

I have one of my rules set as:
PHP Code:
'topic' => [
            'rules' => 'alpha_numeric_punct',
        ], 

When the 'topic' field is let blank it fails validation despite 'required' not being set as a rule.

If I remove the validation rule completely then the validation passes as it should, but this means that there is no validation on the field. 
The same behaviour exists on all my fields. 

I thought fields were not required by default (otherwise, why would we need the 'required' rule). 

I would really appreciate any explanation or suggestion.
Reply
#2

Ah, just found 'permit_empty' rule which achieves the behavior I'm after.
So, 'required' is not necessary on when many of the other rules are set.
I think this is a change from Code Igniter 3.
Reply
#3

I got the same situation with `valid_email`.

It seems CI4 format validation rules do not permit empty string.
So we must add `permit_empty` if we want to permit empty.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB