Wednesday, March 9, 2022

[FIXED] Validation flashdata error is not displaying in CodeIgniter

Issue

Here is my login method inside the controller, Here I am setting a flash message for the validation errors -

public function login(){
    $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[3]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[3]');

    if($this->form_validation->run() == FALSE){
        $data = array(
          'errors' => validation_errors()
        );
        $this->session->set_flashdata($data);
        redirect('home');
    }
}

Here id the code to display those errors -

<?php if($this->session->flashdata('errors')): ?>
    <?php echo $this->session->flashdata('errors');?>

<?php endif; ?>

I don't know what is wrong, Error message is not displaying.


Solution

I hope work this process

if($this->form_validation->run() == FALSE){
    $this->session->set_flashdata('name','Your message');
    redirect('home');
}
<?php if($this->session->flashdata('name')): ?>
<?php echo $this->session->flashdata('name');?>    
<?php endif; ?>


Answered By - Masud_ma

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.