Welcome Guest, Not a member yet? Register   Sign In
Validation Class passing field name
#3

(This post was last modified: 11-20-2021, 08:17 AM by sevmusic.)

(11-19-2021, 03:25 AM)InsiteFX Wrote: CodeIgniter 4 Validation Library - eithRequest()

SEE: how it's handaling error messages.

I've scoured that page and I did not seeing anything on how to get the label to the Validation class.

But your direction gave me an idea which wasn't spelled out in the documents (some of us need real world examples beaten over our heads).

So here's the solution for anyone wanting it.

MyController.php
PHP Code:
$this->validation->setRules([
    'first_name' => [
        'label' => 'First Name',
        'rules' => 'myFieldCheck'
        'errors' => [
            'myFieldCheck' => 'The {field} field needs to be last least 1 character long.'
        ]
    ],
]); 

MyValidationRules.php
PHP Code:
class MyValidationRules
{
    public function myFieldCheck(string $strstring &$error null): bool
    
{
        if(!strlen(trim($str)) > 0){
           return false;
       } else {
            return true;
        }
    }


Thanks for the help!
Reply


Messages In This Thread
Validation Class passing field name - by sevmusic - 11-18-2021, 12:10 PM
RE: Validation Class passing field name - by sevmusic - 11-20-2021, 07:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB