I’m trying to use Cake\Validation\Validator but I can’t get my form to validate properly. I’m requiring the presence of all form elements but only the username and email fields are validating. The array being displayed on the image below shows the key/value pairs being submitted.
Anyone any idea what the problem could be?
return $validator
->requirePresence('username', 'This field is required')
->notEmptyString('username', 'Username is required')
->minLength('username', 3, 'Too short')
->maxLength('username', 60, 'Too long')
->requirePresence('password', 'This field is required')
->notEmptyString('password', 'Password is required')
->minLength('password', 8, 'Too short')
->maxLength('password', 60, 'Too long')
->requirePresence('email', 'This field is required')
->email('email', false, 'E-Mail must be valid')
->requirePresence('first_name', 'This field is required')
->notEmptyString('first_name', 'Input required')
->requirePresence('last_name', 'This field is required')
->notEmptyString('last_name', 'Input required');
There is a difference between “the field has not been submitted” and “the field has been submitted, but the value is empty”. Can you try it with Postman and post a screenshot?
Just using Postman seemed to sort this straight away! Where does the message “This field is required” get set? I’m setting it in the validator but when I change it the change isn’t reflected when I submit the request to postman.