Welcome Guest, Not a member yet? Register   Sign In
Not receiving any validation error on view page
#1

My application runs on the latest version of CI, but somehow I am not getting any validation error on my view page.
view page code:-
Code:
<form method="POST" action="<?= site_url('service-providers'); ?>" accept-charset="UTF-8">
   <?= view('AdminProfile\Views\_notifications') ?>
                        <div class="form-group">
                            <label for="email">Email <span class="mandet">*</span></label>
                            <input type="text" class="form-control" name="email" id="email" value="<?= old('email') ?>" placeholder="Enter Email">
                            <span class="text-danger"><?= $validation->showError('email'); ?></span>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-12">
                                <label for="password">Password <span class="mandet">*</span></label>
                                <input type="password" class="form-control" name="password" id="password" placeholder="Enter Password">
                                <span class="text-danger"><?= $validation->showError('password'); ?></span>
                            </div>
                        </div>
                        <?= csrf_field(); ?>
                        <button class="btn btn-outline-success my-2 my-sm-0  login-btn" type="submit">Login</button>
                    </form>

and this is the code of the controller
PHP Code:
public function attemptLogin()
 {
 
$rules = [
 
'email' => 'required',
 
'password' => 'required|min_length[8]',
 ];

 if (! 
$this->validate($rules)) {
 return 
redirect()->back()->withInput();
 }


on the controller, I can print the error but on the view page, it is coming blank.
Learning Codeigniter 
Reply
#2

Read https://codeigniter4.github.io/CodeIgnit...ion-errors
Reply
#3

(This post was last modified: 04-14-2023, 05:48 AM by SubrataJ.)

(04-14-2023, 02:10 AM)kenjis Wrote: Read https://codeigniter4.github.io/CodeIgnit...ion-errors

I tried, but I am not getting my old input value as well as any errors, although I am using return redirect()->back()->withInput();

fixed it, thanks for the resource.

this was helpful https://github.com/kenjis/ci4-validation.../form2.php
Learning Codeigniter 
Reply
#4

What was the issue?
Reply
#5

(04-14-2023, 11:22 PM)kenjis Wrote: What was the issue?

Instead of using set_value() and show_validation_error(), I was using old() and $validation->getError(). It was foolish of me I did not read the documentation properly. validation_show_error
Learning Codeigniter 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB