Posts: 39
Threads: 11
Joined: Oct 2016
Reputation:
0
11-19-2016, 08:44 AM
(This post was last modified: 11-19-2016, 08:45 AM by superior.)
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?
Posts: 29
Threads: 0
Joined: Dec 2014
Reputation:
1
there is no "trim" validation rule in ci4
Posts: 39
Threads: 11
Joined: Oct 2016
Reputation:
0
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.
Posts: 29
Threads: 0
Joined: Dec 2014
Reputation:
1
Please put Your controller code here, and what error that showing on the first run?
Posts: 39
Threads: 11
Joined: Oct 2016
Reputation:
0
(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');
Posts: 29
Threads: 0
Joined: Dec 2014
Reputation:
1
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. )
Posts: 39
Threads: 11
Joined: Oct 2016
Reputation:
0
11-19-2016, 05:49 PM
(This post was last modified: 11-19-2016, 05:50 PM by superior.)
(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.
Posts: 29
Threads: 0
Joined: Dec 2014
Reputation:
1
(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. )
Posts: 39
Threads: 11
Joined: Oct 2016
Reputation:
0
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!
|