CodeIgniter Forums
Form validation not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Form validation not working (/thread-67332.html)



Form validation not working - patelprem1992 - 02-11-2017

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


RE: Form validation not working - albertleao - 02-11-2017

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.


RE: Form validation not working - qury - 03-23-2017

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 →



RE: Form validation not working - qury - 03-28-2017

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');
 
       }
 
   }




RE: Form validation not working - donpwinston - 04-19-2017

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.


RE: Form validation not working - ciadmin - 04-19-2017

(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/libraries/validation.html#loading-the-library


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



RE: Form validation not working - donpwinston - 04-19-2017

(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/libraries/validation.html#loading-the-library


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

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