Welcome Guest, Not a member yet? Register   Sign In
Issue with form validation
#4

(This post was last modified: 09-30-2018, 12:27 AM by unodepiera.)

(09-27-2018, 12:47 AM)happyape Wrote: Here is my code -

This gives me "Undefined property: App\Controllers\Home::$validation" error.
Code:
   public function login()
{

       if (! $this->validate([
           'email' => 'required',
           'password'  => 'required'
       ])) {
           echo Services::plates('login', [
               'validation' => $this->validation
           ]);
       } else {
           //'title' => $this->request->getVar('title'),
       }

}

However, I can fix this error using this b
Code:
$validation =  \Config\Services::validation();
but I think as per documentation I should be able to pass validation object as above.

Another issue is in the view
Code:
   <?= $validation->listErrors() ?>

It just shows me error messages for the given rules above without even submitting the form along with the name of the validation view file name.

Code:
1 ROOTPATH/system/Validation/Views/list.php

   The email field is required.
   The password field is required.

What am I doing wrong?

Validation works fine for me:

Some Controller:
PHP Code:
$validation $this->validate(Array rules, Array messages);
if ( ! 
$validation) {
 
   return redirect('/register')->withInput();


withInput method from CodeIgniter Core:
PHP Code:
public function withInput()
{
    
$session $this->ensureSession();

    
$input = [
        
'get'     => $_GET ?? [],
        
'post'     => $_POST ?? [],
    ];

    
$session->setFlashdata('_ci_old_input'$input);

    
// If the validator has any errors, transmit those back
    // so they can be displayed when the validation is
    // handled within a method different than displaying the form.
    
$validator Services::validation();
    if (! empty(
$validator->getErrors()))
    {
        
$session->setFlashdata('_ci_validation_errors'serialize($validator->getErrors()));
    }

    return 
$this;


Register View:
PHP Code:
<?php echo service('validation')->listErrors() ?>

If you want access to validator from some controller you can do it:
[Image: 2ZqiHIG.png]
Reply


Messages In This Thread
Issue with form validation - by happyape - 09-27-2018, 12:47 AM
RE: Issue with form validation - by InsiteFX - 09-27-2018, 04:04 AM
RE: Issue with form validation - by happyape - 09-27-2018, 05:32 AM
RE: Issue with form validation - by unodepiera - 09-30-2018, 12:26 AM
RE: Issue with form validation - by InsiteFX - 09-30-2018, 03:57 AM
RE: Issue with form validation - by unodepiera - 09-30-2018, 10:48 AM
RE: Issue with form validation - by happyape - 09-30-2018, 02:46 PM
RE: Issue with form validation - by unodepiera - 09-30-2018, 10:47 PM
RE: Issue with form validation - by happyape - 10-01-2018, 12:47 AM
RE: Issue with form validation - by unodepiera - 10-01-2018, 01:18 AM
RE: Issue with form validation - by happyape - 10-01-2018, 01:55 AM
RE: Issue with form validation - by dave friend - 10-01-2018, 09:16 AM
RE: Issue with form validation - by InsiteFX - 10-01-2018, 10:40 AM
RE: Issue with form validation - by dave friend - 10-01-2018, 11:05 AM
RE: Issue with form validation - by InsiteFX - 10-01-2018, 12:08 PM
RE: Issue with form validation - by Ekley - 10-11-2019, 07:22 AM
RE: Issue with form validation - by Bart Goossens - 08-22-2020, 08:58 AM
RE: Issue with form validation - by jreklund - 08-22-2020, 12:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB