• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation form

#1
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
Need a free blog? try Mitha Blog. Here You can create a free website or build a blog with dozens of free, customizable, mobile-ready designs and themes.
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?
Need a free blog? try Mitha Blog. Here You can create a free website or build a blog with dozens of free, customizable, mobile-ready designs and themes.
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.

Need a free blog? try Mitha Blog. Here You can create a free website or build a blog with dozens of free, customizable, mobile-ready designs and themes.
Reply

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

Need a free blog? try Mitha Blog. Here You can create a free website or build a blog with dozens of free, customizable, mobile-ready designs and themes.
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.