Welcome Guest, Not a member yet? Register   Sign In
validate form CI4
#1

in ci3 $this->load->library('form_validation');
in ci4??
Reply
#2

Here's the User Guide page for that
Reply
#3

helper(['form', 'url']);

               if (! $this->validate([]))
               {
                       echo view('Signup', [
                               'validation' => $this->validation
                       ]);
               }
               else
               {
                       echo view('Success');
               }
 
is a exceptionHandler
Reply
#4

What message is the Exception saying?
Reply
#5

"Argument 1 passed to helper() must be of the type string, array given, called in C:\xampp\htdocs\ci4m_framework\application\Controllers\Login.php on line 10"
line 10 -> helper(['form', 'url']);
my source:
    public function index()
    {
        //echo view('w_login');
                $validation =  \Config\Services::validation();
                helper(['form', 'url']);
                //library(['validation']);
                
//                
//                
//                
//                
//                
//                
//                $validation->setRules([
//    'id' => 'required',
//    'pw' => 'required|min_length[10]'
//]);
//                
                if (! $this->validate([]))
                {
                        echo view('w_login', [
                                'validation' => $this->validation
                        ]);
                }
                else
                {
                        echo view('w_login');
                }
                
    }
Reply
#6

modified helper(['form', 'url']); in helper('form', 'url');

in line if (! $this->validate([]))
exception
"Call to undefined method Login::validate()"
Reply
#7

Quote:"Argument 1 passed to helper() must be of the type string, array given, called in C:\xampp\htdocs\ci4m_framework\application\Controllers\Login.php on line 10"

It tells you exactly what the error is there. The `helper()` method doesn't currently allow more than one helper to be loaded at a time. Hence, it requires a string, not an array. It probably should, and I'll make an issue to that affect to remind me, but doesn't currently. In your case, it's not biggie - the url helper is loaded by default.
Reply
#8

it works fine.

@Lonnie You already did it (https://github.com/bcit-ci/CodeIgniter4/...40c1b7b97b)

@gra are you sure to use the latest version ?
Reply
#9

used : https://github.com/bcit-ci/CodeIgniter4.git -> master
Reply
#10

(This post was last modified: 04-09-2018, 12:11 AM by gabpnr.)

ok, no commit on this branch since 24 Jun 2016 and helper() accept arrays since 20 Sep 2016

use the develop branch.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB