CodeIgniter Forums

Full Version: Form validation not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I trying many things to do form validation but it still not working and also documentation is not proper or correct,
can you please give a proper example with a code.
otherwise i thing i am wasting my times
We can't really help you if you don't explain what your problem is. What's not working? Can you post some of your code? I assure you it's working and you're probably using it incorrectly.
Hi, i ran into this same issue.

To replicate it, use a fresh install of CI4,
Copy and paste the code example from the user guide

Code:
TypeError
Argument 2 passed to CodeIgniter\Validation\Validation::setRules() must be of the type array, null given, called in /var/www/htdocs/CODEIGNITER/ion.info/system/Controller.php on line 187 search →
Hi,

I think i cracked this, so the example was modified as per below and it works:

PHP Code:
<?php
namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
Config\Services;

class 
Form extends Controller {

 
   public $validation;

 
   public function index()
 
   {
 
       helper(['form''url']);

 
       $this->validation = \Config\Services::validation();

 
       $this->validation->setRules([
 
           'username' => 'required'
 
       ]);

 
       if (!$this->validation->withRequest($this->request)->run())
 
       {
 
           echo view('Signup', [
 
               'validation' => $this->validation
            
]);
 
       } else
 
       {
 
           echo view('Success');
 
       }
 
   }

helper('form');
$validator = new \CodeIgniter\Form\Validator();

I get a class not found error for Validator. I take it this is not the way to do it but the docs do it this way.
(04-19-2017, 09:20 AM)donpwinston Wrote: [ -> ]helper('form');
$validator = new \CodeIgniter\Form\Validator();

I get a class not found error for Validator. I take it this is not the way to do it but the docs do it this way.

Er, the docs don't do it your way... https://bcit-ci.github.io/CodeIgniter4/l...he-library


Code:
$validator = \Config\Services::validation();
(04-19-2017, 10:01 AM)ciadmin Wrote: [ -> ]
(04-19-2017, 09:20 AM)donpwinston Wrote: [ -> ]helper('form');
$validator = new \CodeIgniter\Form\Validator();

I get a class not found error for Validator. I take it this is not the way to do it but the docs do it this way.

Er, the docs don't do it your way... https://bcit-ci.github.io/CodeIgniter4/l...he-library


Code:
$validator = \Config\Services::validation();

The tutorial does it differently. https://bcit-ci.github.io/CodeIgniter4/t...items.html