Welcome Guest, Not a member yet? Register   Sign In
Form Validation not Working 4.2.12 -> 4.3.1
#1

(This post was last modified: 01-15-2023, 08:12 AM by kodokrawa.)

Need help
After Update 4.2.12 to 4.3.1
Validation error not working, is there code need to change?
Because error validation not show
Please

Controler BaseController.php
PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
Psr\Log\LoggerInterface;
use 
CodeIgniter\HTTP\CLIRequest;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *    class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 */
abstract class BaseController extends Controller
{
    /**
    * Instance of the main Request object.
    *
    * @var CLIRequest|IncomingRequest
    */
    protected $request;

    /**
    * An array of helpers to be loaded automatically upon
    * class instantiation. These helpers will be available
    * to all other controllers that extend BaseController.
    *
    * @var array
    */
    protected $helpers = [];

    /**
    * Constructor.
    */
    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        // Preload any models, libraries, etc, here.

        // E.g.: $this->session = \Config\Services::session();

        $this->validation = \Config\Services::validation(); //Undefined property '$validation'.intelephense(1014)
        $this->session = \Config\Services::session(); //Undefined property '$session'.intelephense(1014)

    }




Controller Login.php
PHP Code:
class Login extends BaseController
{

    public function index()
    {
        $data['validation'] = \Config\Services::validation();
        return view('login'$data);
    }
.... 

PHP Code:
public function ceklogin()
    {

        if (!$this->validate([
            'wa' => [
                'rules' => 'trim|required',
                'errors' => [
                    'required' => 'Nomor Whatsapp harus diisi',
                ]
            ],
            'password' => [
                'rules' => 'trim|required',
                'errors' => [
                    'required' => 'Password harus diisi',
                ]
            ],

        ])) {
            
            
return redirect()->to('login')->withInput();
        }
  }



My View login_view.php
PHP Code:
<div class="mb-3">
                        <label for="wa" class="form-label m-0">Nomor Whatsapp</label>
                        <input type="number" class="form-control <?= ($validation->hasError('wa')) ? 'is-invalid'  : ''; ?>" name="wa" id="wa" aria-describedby="wa"  autocomplete="off">
                        <div class="invalid-feedback">
                            <?= $validation->getError('wa'); ?>
                        </div>
                    </div> 
Reply


Messages In This Thread
Form Validation not Working 4.2.12 -> 4.3.1 - by kodokrawa - 01-15-2023, 07:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB