• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with passing variable from controller to view

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!


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

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


function keep_tuned() {
   // validate form input
   $valid = $this->form_validation->run();
   if($valid == false) {
   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'));
    if($query = $this->Model_launch->enquiry($name,$email,$company))

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.