• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Fix Form Validation Error in Codeigniter 4??

#1
I have used Codeigniter 4 Form Validation in login form.Also,the validation form works well or good. When the login page is loaded Before that imported field also is showed the errors. In below ,I inserted the controller and view codes that relate to section the login. I check different ways but i didnt get way that to solve that. Please guidance me for solve it.
User Controller:
Code:
<?php namespace App\Controllers;

use App\Models\UserModel;

class User extends BaseController
{
    public function index()
    {
        echo "User index";
        // Load views
//        echo view('static/header');
//        echo view('front/all');
//        echo view('static/footer');
    }

    public function login()
    {
        helper('form');

        $val = $this->validate([
            'username' => 'required',
            'password' => 'required',
        ]);

        if (!$val)
        {
            echo view('front/login', [
                'validation' => $this->validator
            ]);
        }
        else
        {
            return redirect()->to('/');
        }

    }

    public function logout()
    {

    }

    public function register()
    {
        // Load views
        echo view('front/register');
    }
}
login.php(login page view):
Code:
<body>
<?= \Config\Services::validation()->listErrors(); ?>
<div class="limiter">
    <div class="container-login100">
        <div class="wrap-login100 p-b-160 p-t-50">
            <?php echo form_open(base_url('user/login'),array('class'=>'login100-form validate-form')); ?>
                    <span class="login100-form-title p-b-43">
                        Login Form
                    </span>

                <div class="wrap-input100 rs1 validate-input">
                    <input class="input100" type="text" name="username">
                    <span class="label-input100">User Name</span>
                </div>


                <div class="wrap-input100 rs2 validate-input">
                    <input class="input100" type="password" name="password">
                    <span class="label-input100">Password</span>
                </div>

                <div class="container-login100-form-btn">
                    <button class="login100-form-btn" type="submit">
                        Login
                    </button>
                </div>

                <div class="text-center w-full p-t-23">
                    <a href="#" class="txt1">
                        Forget Password?
                    </a>
                </div>

                <div class="text-center w-full p-t-23">
                    <a href="<?php echo base_url('user/register'); ?>" class="txt1">
                        SignUp
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>

</body>
Output(Login Page First Time Visit): localhost/user/login
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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