Can anyone tell me why flashdata is not immediately available? Is it only available once the page has been resent? I am using form validation for form fields and flashdata for error messages. If there is an error I want the fields to be filled in with the $_POST data, which CI does easily, however, the flashdata seems to only be recognised once I refresh (through redirect()) which destroys the $_POST data.
If I remove the redirect then validation errors and automatic re-entering of posted values works, but no flashdata message.
controlller:
view:
If I remove the redirect then validation errors and automatic re-entering of posted values works, but no flashdata message.
controlller:
Code:
// Validation rules $this->form_validation->set_rules('name', 'username', 'required|alpha_dash'); $this->form_validation->set_rules('pass', 'password', 'required|alpha_dash'); // Check form has been submitted with valid form info if ($this->form_validation->run()) { $name = $this->input->post('name'); $pass = $this->input->post('pass'); ... // Return if name and password was not found if ($check===FALSE) { $this->session->set_flashdata('message_type', 'warning'); $this->session->set_flashdata('message', 'Username not found.'); // Success } else { ... $this->session->set_flashdata('message_type', 'information'); $this->session->set_flashdata('message', 'Logged in.'); } // Success or fail redirect page redirect('user/login'); exit(); } // Load Page $this->load->view('v_user_login');
Code:
<?php if($this->session->flashdata('message')) : ?> <div class="<?=$this->session->flashdata('message_type')?>"> <h3><span> </span><?=$this->session->flashdata('message')?></h3> </div> <?php endif; ?> <h1>User Login</h1> <?=form_open('user/login')?> <?=form_fieldset('Login Form')?> <div class="textfield"> <?=form_label('Username','name')?> <?=form_input('name', set_value('name'))?> <?=form_error('name')?> </div> <div class="textfield"> <?=form_label('Password', 'pass')?> <?=form_password('pass')?> <?=form_error('pass')?> </div> <div class="buttons"> <?=form_submit('login', 'Login')?> </div> <?=form_fieldset_close()?> <?=form_close()?>
Comment