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

(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?
Reply
#2

there is no "trim" validation rule in ci4
Tafsir NU adalah sebuah aplikasi yang berisi kumpulan kajian kitab kuning yang disampaikan oleh Kiai Nahdhotul Ulama seperti Gus Baha, gus mus, dan kiai lainnya dalam format audio.
Reply
#3

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.
Reply
#4

Please put Your controller code here, and what error that showing on the first run?
Tafsir NU adalah sebuah aplikasi yang berisi kumpulan kajian kitab kuning yang disampaikan oleh Kiai Nahdhotul Ulama seperti Gus Baha, gus mus, dan kiai lainnya dalam format audio.
Reply
#5

(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'); 
Reply
#6

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.

Tafsir NU adalah sebuah aplikasi yang berisi kumpulan kajian kitab kuning yang disampaikan oleh Kiai Nahdhotul Ulama seperti Gus Baha, gus mus, dan kiai lainnya dalam format audio.
Reply
#7

(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.
Reply
#8

(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.

Tafsir NU adalah sebuah aplikasi yang berisi kumpulan kajian kitab kuning yang disampaikan oleh Kiai Nahdhotul Ulama seperti Gus Baha, gus mus, dan kiai lainnya dalam format audio.
Reply
#9

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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB