• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation: getErrors not return $var = '' instead just remove it

#1
hello again, here my test code

controller:
PHP Code:
<?php

namespace App\Controllers;

class 
Test extends BaseController
{
    public function index()
    {
        $data = [
            'submit_url'        => base_url('test/submit'),
            'error'             => $this->session->getFlashdata(),
            'csrf_token'        => csrf_token(),
            'csrf_hash'         => csrf_hash()
        ];
        //echo view('inc/header');
        echo $this->parser->setData($data)->render('test');
        //echo view('inc/footer');
    }

    public function submit()
    {
        $this->validation->setRules([
            'name'      => 'required|alpha',
            'email'     => 'required|valid_email',
            'password'  => 'required',
        ]);
        $valid $this->validation->withRequest($this->request)->run();
        if ($valid === false) {
            return redirect()->back()->with('message'$this->validation->getErrors());
        }
        $email $this->request->getPost('email');
        return $email;
    }


view:
PHP Code:
{error}
{
name}
{
email}
{
password}
{/
error}

<
form class="ui form" method="post" action="{submit_url}">
    <div class="field">
        <label>Name</label>
        <input type="text" name="name" placeholder="Name">
    </div>
    <div class="field">
        <label>Email</label>
        <input type="text" name="email" placeholder="Email">
    </div>
    <div class="field">
        <label>Password</label>
        <input type="password" name="password" placeholder="Password">
    </div>
    <input type="hidden" name="{csrf_token}" value="{csrf_hash}" />
    <button class="ui button" type="submit">Submit</button>
</
form


the result if validation have error:
   

what I expected is like codeigniter 3 which all error should be in string rather than removed when have no errors
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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