简体   繁体   中英

validation errors not net to the flashdata in codeigniter

I'm trying to set validation error to the my form using flashdata in codeigniter but i cannot see the error in a view here is my code of view section. I had already read other relative questions close to my this problem but i'm not found a solution!

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

                <?php $attributes = array('id'=>'admin_login','class'=>'form-horizontal'); ?>
                <?php echo form_open('admin/login', $attributes); ?>
                    <div class="form-group">
                        <?php
                        $lbl = array('class'=>'col-sm-12 col-lg-12 col-md-12 col-xs-12 control-label');
                        echo form_label('Email','admin_login',$lbl); ?>
                        <div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
                            <?php $data = array('
                                class'=> 'form-control col-sm-12 col-lg-12 col-md-12 col-xs-12',
                                'name'=> 'email',
                                'placeholder'=>'Enter your email'
                            ); ?>
                            <?php echo form_input($data); ?>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        echo form_label('Password','admin_login',$lbl); ?>
                        <div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
                            <?php $data = array('
                                class'=> 'form-control',
                                'name'=> 'password',
                                'placeholder'=>'Password'
                            ); ?>
                            <?php echo form_password($data); ?>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
                            <?php $data = array('
                                class'=> 'btn btn-success btn-md center mt-2',
                                'name'=> 'submit',
                                'placeholder'=>'Password',
                                'value'=>'LOGIN',
                                'type'=>'submit'
                            ); ?>
                            <center>
                                <?php echo form_submit($data); ?>
                            </center>
                        </div>
                    </div>
                <?php echo form_close(); ?>

This is my controller part it is name of 'admin' method name is login

        public function login(){

            $this->form_validation->set_rules('email','Email','required');
            $this->form_validation->set_rules('password','Password','required');

            // check the form has any error (any miss of rules we set in above codes

                   if($this->form_validation->run() == FALSE){
                    $this->session->set_flashdata('errors', 
                    validation_errors());

    //              $this->session->set_flashdata('name','Your message');
    //              $errors = validation_errors();
    //              $this->session->set_flashdata('form_error', $errors);

    //              $this->session->set_flashdata('name','Your message');
    //              $data = array('errors'=> validation_errors());
    //              set_userdata() is regular way to set session, it need manually unset, there for we use flashdata
    //              $this->session->set_flashdata($data);
            }else{
                echo "its all good";
            }
        }

i tried so many codes, i commented out what i used so far. I set in autoload section session library also $autoload['libraries'] = array('database','form_validation','session');

Please tell me what is the wrong here.

Please try with the below code.

public function login(){
    $this->form_validation->set_rules('email','Email','required');
    $this->form_validation->set_rules('password','Password','required');

    if($this->form_validation->run() == true){
       echo "its all good";
    }else{
       $this->session->set_flashdata('errors', validation_errors());
    }
    $this->load->view('Your View Page');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM