• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form validation not working

#1
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
Reply

#2
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.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply

#3
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 →
Reply

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

Reply

#5
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.
Simpler is always better
Reply

#6
(04-19-2017, 10: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();
Reply

#7
(04-19-2017, 11:01 AM)ciadmin Wrote:
(04-19-2017, 10: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
Simpler is always better
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.