Welcome Guest, Not a member yet? Register   Sign In
Problem with passing variable from controller to view
#1

[eluser]condoace[/eluser]
I am trying to use a jquery modal window/ pop up window after the user has submitted the form and it was successful. I have created a flash data from the controller but for some reason the view file does not recognise the flash data or something is going wrong.. please have a look at my code, any ideas would be helpful!

VIEW

Code:
<?php if ($this->session->flashdata('result') != '') {

echo '<type="text/javascript"> // I just remove "script" as the forum wont allow it
$.prompt("finished");
[removed]'; // "script" is here, forum has removed it

}?&gt;

CONTROLLER
Code:
function keep_tuned() {
  
  
   $this->load->library('form_validation');
  
   // validate form input
  
   $this->form_validation->set_rules('name','Name','trim|required');
  
   $this->form_validation->set_rules('email','Email','trim|required|valid_email');
  
   $this->form_validation->set_rules('company','Company','trim|required');
    
   $valid = $this->form_validation->run();
  
   if($valid == false) {
    
    $this->load->view('view_launch.php');
            
   }
  
   else {
    
    $name = mysql_real_escape_string($this->input->post('name'));
    
    $email = mysql_real_escape_string($this->input->post('email'));
    
    $company = mysql_real_escape_string($this->input->post('company'));
    
    $this->load->model('Model_launch');
    
    if($query = $this->Model_launch->enquiry($name,$email,$company))
    {
          
     $this->session->set_flashdata('result','test');
    
     $this->load->view('view_launch',$data);
    
    
    }
    
    else
    {  
    
     $this->load->view('view_launch');
    
    }  
      
   }
    
  }
#2

[eluser]Unknown[/eluser]
Session flashdata is available for the next server request that is made. From your code you are setting the flashdata and then loading the view not redirect or reloading the page you intend to view.

From the docs

Quote:CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").

So in short you'll either need to redirect back to your controller method and show the flashdata there or just pass the validation error messages direct to the view with a normal variable.




Theme © iAndrew 2016 - Forum software by © MyBB