I'm running codeigniter 4.1.5 and php 8.1.0 and when i try to input data this is the error i got
Uncaught ErrorException: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in C:\xampp\htdocs\cikaryawan\system\Validation\FormatRules.php:253 Stack trace:
- #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler()
- #1 C:\xampp\htdocs\cikaryawan\system\Validation\FormatRules.php(253): strtolower()
- #2 C:\xampp\htdocs\cikaryawan\system\HTTP\RequestTrait.php(151): CodeIgniter\Validation\FormatRules->valid_ip()
- #3 C:\xampp\htdocs\cikaryawan\app\Views\errors\html\error_exception.php(206): CodeIgniter\HTTP\Request->getIPAddress()
- #4 C:\xampp\htdocs\cikaryawan\system\Debug\Exceptions.php(229): include('...')
- #5 C:\xampp\htdocs\cikaryawan\system\Debug\Exceptions.php(232): CodeIgniter\Debug\Exceptions->CodeIgniter\Debug{closure}()
- #6 C:\xampp\htdocs\cikaryawan\system\Debug\Exceptions.php(116): CodeIgniter\Debug\Exceptions->render()
- #7 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler()
- #8 {main} in my .env folder
CI_ENVIRONMENT = development
database.default.hostname = localhost
database.default.database = cikaryawanauth
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
database.default.DBPrefix =
this is my register.php
<body>
<div class="container">
<div class="row" style="margin-top:45px">
<div class="col-md-4 col-md-offset-4">
<h4>Sign Up</h4>
<hr>
<form action="<?= base_url('auth/save') ?>" method="post">
<?= csrf_field(); ?>
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" name="name" placeholder="Enter your name" value="<?= set_value('name'); ?>">
<span class="text-danger"><?= isset($validation) ? display_error($validation, 'name') : '' ?></span>
</div>
<div class="form-group">
<label for="">Email</label>
<input type="email" class="form-control" name="email" placeholder="Enter your email" value="<?= set_value('email'); ?>">
<span class=" text-danger"><?= isset($validation) ? display_error($validation, 'email') : '' ?></span>
</div>
<div class="form-group">
<label for="">Password</label>
<input type="password" class="form-control" name="password" placeholder="Enter password">
<span class="text-danger"><?= isset($validation) ? display_error($validation, 'password') : '' ?></span>
</div>
<div class="form-group">
<label for="">Confirm Password</label>
<input type="password" class="form-control" name="cpassword" placeholder="Confirm password">
<span class="text-danger"><?= isset($validation) ? display_error($validation, 'cpassword') : '' ?></span>
</div>
<div class="form-group">
<button class="btn btn-primary btn-block" type="submit">Sign Up</button>
</div>
<a href="<?= site_url('auth/') ?>">I already have account, login now</a>
</form>
</div>
</div>
</div>
</body>
this is my auth.php as controller
<?php
namespace App\Controllers;
class Auth extends BaseController
{
public function __construct()
{
helper(['url', 'form']);
}
public function index()
{
return view('auth/login');
}
public function register()
{
return view('auth/register');
}
public function save()
{
$validation = $this->validate([
'name' => [
'rules' => 'required',
'errors' => [
'required' => 'Your name is required'
]
],
'email' => [
'rules' => 'required|valid_emails|is_unique[users.email]',
'errors' => [
'required' => 'Email is required',
'valid_email' => 'You must enter a valid email',
'is_unique' => 'Email already taken'
]
],
'password' => [
'rules' => 'required|min_length[5]|max_length[12]',
'errors' => [
'required' => 'Password is required',
'min_lenght' => 'Password must have atleast 5 character',
'max_lenght' => 'Password must not exceed 12 character'
]
],
'cpassword' => [
'rules' => 'required|min_length[5]|max_length[12]|matches[password]',
'errors' => [
'required' => 'Password is required',
'min_lenght' => 'Password must have atleast 5 character',
'max_lenght' => 'Password must not exceed 12 character',
'matches' => 'Confirms password not matches to password'
]
]
]);
if (!$validation) {
return view('auth/register', ['validation' => $this->validator]);
} else {
$name = $this->request->getPost('name');
$email = $this->request->getPost('email');
$password = $this->request->getPost('password');
$values = [
'name' => $name,
'email' => $email,
'password' => $password,
];
$userModels = new \App\Models\UsersModel();
$query = $userModels->insert($values);
if (!$query) {
return redirect()->back()->with('fail', 'something went wrong');
} else {
return redirect()->to('register')->with('success', 'You are now registered');
}
}
}
}
this is what i put in form_helper.php in helpers folder
<?php
function display_error($validation, $field)
{
if ($validation->hasError($field)) {
return $validation->getError($field);
} else {
return false;
}
}
what did i do wrong?