PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] Validation flashdata error is not displaying in CodeIgniter

 March 09, 2022     codeigniter, flash-message, php, session     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing