Welcome Guest, Not a member yet? Register   Sign In
model validationRules for nullable fields?
#2

(This post was last modified: 01-14-2022, 02:20 PM by BilltheCat.)

You could always wrap your rules in normal PHP logic... I'm not sure what rules you could apply in this case, but this might be what you're looking for:

PHP Code:
$post $this->request->getPost();
$rules = [
        'username' => [
            'rules'  => 'required',
            'errors' => [
                'required' => 'You must choose a Username.',
            ],
        ],
        'email'    => [
            'rules'  => 'required|valid_email',
            'errors' => [
                'valid_email' => 'Please check the Email field. It does not appear to be valid.',
            ],
        ],
    ];


if(
is_int($post['fieldname']) || is_numeric($post['fieldname']) is_null($post['fieldname'])) {
$rules['fieldname'] = [
            'rules'  => 'is_unique'
        ];
}
$validation->setRules($rules); 
Reply


Messages In This Thread
RE: model validationRules for nullable fields? - by BilltheCat - 01-14-2022, 02:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB