0

I am making a form in CI and submit the form. After submitting, the page redirects to another page but before redirect I am use set_flashdata but without using set_flashdata my form submits successfully and page redirects to another page. But when using set_flashdata then it doesn't redirect and loads a blank page and then the site stops working and all another pages of my site load a blank page.

{

    $this->load->helper('file');
    $data = $this->input->post('data');

    if ( ! write_file('./application/modules/widgets/'.$alias.'.php', $data))
    {
         //$this->session->set_flashdata('msg', '<div class="alert alert-error">'.lang_key('unable_to_write_widget').'</div>');
    }
    else
    {
         //$this->session->set_flashdata('msg', '<div class="alert alert-success">'.lang_key('widget_data_updated').'</div>');
    }           
}

redirect(site_url('admin/widgets/edit/'.$alias));
WOUNDEDStevenJones
  • 5,150
  • 6
  • 41
  • 53
akash jha
  • 1
  • 4
  • Why do you have mysql and laravel tagged when they aren't in use? Have you checked your server error logs? – aynber May 08 '18 at 17:08
  • Maybe the `value` part of flashdata can't be HTML? What happens if you try `$this->session->set_flashdata('msg', 'success');` as a test? The reason other pages will load a blank page after this is set is because your flashdata is being set. So I think if you get a blank page and then clear cookies and reload the page it should work again. – WOUNDEDStevenJones May 08 '18 at 17:08
  • The blank page indicates a PHP error and you likely don't have errors being output: https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – WOUNDEDStevenJones May 08 '18 at 17:14
  • change index.php env to development to enable err reporting and get back to us – Alex May 08 '18 at 17:16

1 Answers1

0

A blank page can mean PHP errors are being suppressed. Set CI_ENV to development and you'll see any PHP errors. (ENV or .htaccess usually, but you can (not recommended) set it in the index.php file too)

Make sure your application/config.php file is properly configured for sessions. If you're using files, make sure the sess_save_path is there and writable by sessions. The last 3-4 version releases will absolutely throw up and die if not configured properly.

I'll assume you've already looked at this, but it's a good reference to toss in here anyway. I mention it because you're saying when you call $this->session everything fails.

https://www.codeigniter.com/user_guide/libraries/sessions.html

Slightly off topic, redirect() can add site_url() so you don't need to do that. Just add you URI.

 redirect('admin/widgets/edit/' . $alias);
Friderich Weber
  • 290
  • 2
  • 12