CodeIgniter Forums
Validation form - 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: Validation form (/thread-66666.html)



Validation form - superior - 11-19-2016

Hello,

When trying to validate my form I think there is going something wrong, required fields shows messages on the first run. But when entering the Firstname and Passwords the Lastname doesn't validate anymore.

The code below is inside:  application/Config/Validation.php
PHP Code:
public $manager = [
    
'Firstname'   => 'trim|required',
    
'Lastname'    => 'trim|required',
    
'Username'    => 'trim|required|valid_email',
    
'Password'    => 'trim|required|min_length[8]',
    
'Passconfirm' => 'trim|required|matches[Password]',
]; 

Is there something wrong, or is this a name conflict with the validation?


RE: Validation form - ridho - 11-19-2016

there is no "trim" validation rule in ci4


RE: Validation form - superior - 11-19-2016

Looked at the Rules file and you are correct, this has been set on the required already. However the problem still occur when removing the trim| from the check.


RE: Validation form - ridho - 11-19-2016

Please put Your controller code here, and what error that showing on the first run?


RE: Validation form - superior - 11-19-2016

(11-19-2016, 02:20 PM)ridho Wrote: there is no "trim" validation rule in ci4

(11-19-2016, 02:36 PM)ridho Wrote: Please put Your controller code here, and what error that showing on the first run?

There is no error shown, the check is skipped when Password has a value.

PHP Code:
$this->validation->run([

    
'Firstname'     => $this->request->getPost('Firstname'),
    
'Lastname'      => $this->request->getPost('Password'),
    
'Username'      => $this->request->getPost('Username'),
    
'Password'      => $this->request->getPost('Password'),
    
'Passconfirm'   => $this->request->getPost('Passconfirm')

], 
'manager'); 



RE: Validation form - ridho - 11-19-2016

I tested with no problem.

The code
PHP Code:
if($validation->run([
 
'Firstname'     => 'John',
 
'Lastname'      => 'Smith',
 
'Username'      => 'john',
 
'Password'      => 'pass',
 
'Passconfirm'   => 'passw'
 
], 'manager'))
 {
 echo 
'Ok';
 }else{ 
 
print_r($validation->getErrors());
 } 

Result
PHP Code:
Array
(
 
   [Username] => The Username field must contain a valid email address.
 
   [Password] => The Password field must be at least  characters in length.
 
   [Passconfirm] => The Passconfirm field does not match the  field.




RE: Validation form - superior - 11-19-2016

(11-19-2016, 02:20 PM)ridho Wrote: there is no "trim" validation rule in ci4

(11-19-2016, 05:05 PM)ridho Wrote: I tested with no problem.

The code
PHP Code:
if($validation->run([
 
'Firstname'     => 'John',
 
'Lastname'      => 'Smith',
 
'Username'      => 'john',
 
'Password'      => 'pass',
 
'Passconfirm'   => 'passw'
 
], 'manager'))
 {
 echo 
'Ok';
 }else{ 
 
print_r($validation->getErrors());
 } 

Result
PHP Code:
Array
(
 
   [Username] => The Username field must contain a valid email address.
 
   [Password] => The Password field must be at least  characters in length.
 
   [Passconfirm] => The Passconfirm field does not match the  field.


It happens when setting the following order:

Firstname

Username
Password
Passconfirm

Then the lastname is skipped from the check, I did not put any value in Lastname that should result in error "The lastname field cannot be empty" but it somehow skipped the check.


RE: Validation form - ridho - 11-19-2016

(11-19-2016, 05:49 PM)superior Wrote: It happens when setting the following order:

Firstname

Username
Password
Passconfirm

Then the lastname is skipped from the check, I did not put any value in Lastname that should result in error "The lastname field cannot be empty" but it somehow skipped the check.

I think the problem is your code, you should check again your code, check your form view.

It's working with empty Lastname value.
PHP Code:
Array
(
    [
Lastname] => The Lastname field is required.
    [
Username] => The Username field must contain a valid email address.
    [
Password] => The Password field must be at least  characters in length.
    [
Passconfirm] => The Passconfirm field does not match the  field.




RE: Validation form - superior - 11-20-2016

I've found the problem in my code, must have been a hard saturdaynight because it's right there. Even in this topic you can see what's wrong with it.

In my #5 reply, take a close look at what i'm posting on Lastname...

Feeling stupid right now for not seeing this before, i'm sorry and thank you for the feedback!