Welcome Guest, Not a member yet? Register   Sign In
Validation Rules Group Error
#1

(This post was last modified: 02-15-2023, 05:48 PM by ailerux.)

I have a 4.0.4 project i am trying to port to 4.3.1 and so far so good except I am getting the error:
I believe 'login' is referring to my controller method authentication/login
 
Code:
login is not a validation rules group


The offending line is here... was there a change between 4.0.4 and 4.3.1 that broke this?

PHP Code:
if (!$validation->withRequest($this->request)->run($_POST'login')) { }


The entire error stack:

Uncaught Error.
{
    "title""CodeIgniter\\Validation\\Exceptions\\ValidationException",
    "type""CodeIgniter\\Validation\\Exceptions\\ValidationException",
    "code"500,
    "message""\"/login\" is not a validation rules group.",
    "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/vendor/codeigniter4/framework/system/Validation/Validation.php",
    "line"619,
    "trace": [
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/vendor/codeigniter4/framework/system/Validation/Validation.php",
            "line"619,
            "function""forGroupNotFound",
            "class""CodeIgniter\\Validation\\Exceptions\\ValidationException",
            "type""::"
        },
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/vendor/codeigniter4/framework/system/Validation/Validation.php",
            "line"118,
            "function""loadRuleGroup",
            "class""CodeIgniter\\Validation\\Validation",
            "type""->"
        },
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/app/Controllers/Authentication.php",
            "line"44,
            "function""run",
            "class""CodeIgniter\\Validation\\Validation",
            "type""->"
        },
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/vendor/codeigniter4/framework/system/CodeIgniter.php",
            "line"934,
            "function""authenticateLoginAjax",
            "class""App\\Controllers\\Authentication",
            "type""->"
        },
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/vendor/codeigniter4/framework/system/CodeIgniter.php",
            "line"499,
            "function""runController",
            "class""CodeIgniter\\CodeIgniter",
            "type""->"
        },
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/vendor/codeigniter4/framework/system/CodeIgniter.php",
            "line"368,
            "function""handleRequest",
            "class""CodeIgniter\\CodeIgniter",
            "type""->"
        },
        {
            "file""/var/www/vhosts/mydomain.com/dev.mydomain.com/public/index.php",
            "line"67,
            "function""run",
            "class""CodeIgniter\\CodeIgniter",
            "type""->"
        }
    ]


This is being called from AJAX:

Code:
$.ajax({
    type: 'POST',
    url: base_url + "/authenticateLoginAjax",
    data: {'username': username,  'password': password},
    dataType: 'json',
    success : function(response) {
        console.log(response.errors);
        if (response.errors === undefined || response.errors.length == 0) {
            window.location = response.url;
        } else {
            setTimeout(function() {
                console.log('errors');
                $('.form-row.messages').hide();
                $('.form-row.messages').removeClass('authenticating').addClass('error').fadeIn();
                $('.form-row.messages span').html(response.errors.username);
            }, 2000);
        }
    }, error : function(jqXHR, exception) {
        var message = 'Uncaught Error.\n' + jqXHR.responseText;
        console.log(message);
    }
});
return false;
Reply
#2

(02-15-2023, 05:40 PM)ailerux Wrote: I believe 'login' is referring to my controller method authentication/login

No, 'login' is the pre-defined group of rules to apply.
See https://codeigniter4.github.io/CodeIgnit...onfig-file
Reply
#3

(This post was last modified: 02-15-2023, 08:11 PM by ailerux.)

This is my Validation.php

PHP Code:
//--------------------------------------------------------------------
 // Rules
//--------------------------------------------------------------------

public $login = [
        'username'    => 'required|valid_email',
        'password'    => 'required'
    ];

    public $login_errors = [
        'username' => [
            'required'    => 'Sorry, those credentials are incorrect',
            'valid_email' => 'Sorry, those credentials are incorrect'
        ],
        'password'    => [
            'required' => 'Sorry, those credentials are incorrect'
        ]
    ];

    public $reset_password = [
        'username'    => 'required|valid_email'
    ];

    public $reset_password_errors = [
        'username' => [
            'required'    => 'Please enter a valid email address',
            'valid_email' => 'Please enter a valid email address'
        ]
    ];

    public $update_password = [
        'password'          => 'required|min_length[10]',
        'password_again'    => 'matches[password]'
    ];

    public $update_password_errors = [
        'password' => [
            'required'    => 'Passwords must be at least 10 characters',
            'min_length'  => 'Passwords must be at least 10 characters'
        ],
        'password_again' => [
            'matches[password]' => 'Your passwords do not match'
        ]
    ]; 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB