Welcome Guest, Not a member yet? Register   Sign In
Need FLASH DATA NEED HELP
#1

[eluser]razerone[/eluser]
HI I am trying to have s div show up on my form for flash data that will only show up when message sent successfully the div i am trying to display at bottom of form is <div class="alert alert-success">Flash Data</div>

I had it going but when did it showed up on the normal contact page as well and the confirmation section redirect. I have read user guide but can't get it right.

Here is my php

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contactus extends MX_Controller {

public function index() {

  $this->load->library('googlemaps');

  $config = array();
  $config['center'] = 'Australia';
  $config['zoom'] = '5';

  $this->googlemaps->initialize($config);

  $data_map['map'] = $this->googlemaps->create_map();

  $this->load->view('header', $data_map);
  $this->load->view('contactus');
  $this->load->view('footer');

}

public function confirmation() {

  $this->load->library('email');
  $this->load->library('googlemaps');
  $this->load->library('session');
  $this->load->library('form_validation');

  $this->form_validation->set_rules('fullname', 'Your Full Name', 'required');
  $this->form_validation->set_rules('email', 'Your Email', 'required|valid_email');
  $this->form_validation->set_rules('subject', 'Your Subject', 'required');
  $this->form_validation->set_rules('message', 'Your Message', 'required');

  if ($this->form_validation->run() == FALSE) {

   $config = array();
   $config['center'] = 'Australia';
   $config['zoom'] = '5';

   $this->googlemaps->initialize($config);

   $data_map['map'] = $this->googlemaps->create_map();

   $this->load->view('header', $data_map);
   $this->load->view('contactus');
   $this->load->view('footer');

  } else {

   $fullname = $this->input->post('fullname');
     $email = $this->input->post('email');
     $subject = $this->input->post('subject');
     $message = $this->input->post('message');
    
    $this->email->set_newline("\r\n");
    $this->email->from($email, $fullname);
    $this->email->to('[email protected]');
    $this->email->subject($subject);
    $msgBody = "Full Name:" . " \n\n" . $fullname . " \n\n" .
          "Email:" . " \n\n" . $email . " \n\n" .
          "Subject:" . " \n\n" . $subject . " \n\n" .
          "Message:" . " \t\n\n" . $message;
    $this->email->message($msgBody);

   if($this->email->send()){

   $config = array();
   $config['center'] = 'Australia';
   $config['zoom'] = '5';

   $this->googlemaps->initialize($config);

   $data_map['map'] = $this->googlemaps->create_map();

   $success['flash'] = $this->session->flashdata('success');
   $this->session->set_flashdata('success', 'Message Has Been Submitted Successfully');

   $this->load->view('header', $data_map);
   $this->load->view('contactus');
   $this->load->view('footer');

   }else{

    echo $this->email->print_debugger();

   }


  }

}
}
#2

[eluser]CroNiX[/eluser]
You didn't post the view, which is where it would be displayed.

What is this doing? I don't see you doing anything with $success after you create it (you don't pass it anywhere or anything), but you try to read the session data here before you actually create the session data.
Code:
$success['flash'] = $this->session->flashdata('success');
$this->session->set_flashdata('success', 'Message Has Been Submitted Successfully');

All you really need here is to set the session data in the controller:
Code:
$this->session->set_flashdata('success', 'Message Has Been Submitted Successfully');

And then display it if it exists in the view:
Code:
$message = $this->session->flashdata('success');
&lt;?php if ($message !== FALSE): ?&gt;
<div class=“alert alert-success”>&lt;?php echo $message; ?&gt;</div>
&lt;?php endif; ?&gt;
#3

[eluser]razerone[/eluser]
[quote author="CroNiX" date="1383411501"]You didn't post the view, which is where it would be displayed.

What is this doing? I don't see you doing anything with $success after you create it (you don't pass it anywhere or anything), but you try to read the session data here before you actually create the session data.
Code:
$success['flash'] = $this->session->flashdata('success');
$this->session->set_flashdata('success', 'Message Has Been Submitted Successfully');

All you really need here is to set the session data in the controller:
Code:
$this->session->set_flashdata('success', 'Message Has Been Submitted Successfully');

And then display it if it exists in the view:
Code:
$message = $this->session->flashdata('success');
&lt;?php if ($message !== FALSE): ?&gt;
<div class=“alert alert-success”>&lt;?php echo $message; ?&gt;</div>
&lt;?php endif; ?&gt;
[/quote]

Sorry for late reply I did work that out last night.

Controller

Code:
$data_success['message_success'] = '<div class="alert alert-success">Your Message Has Been Recived Will Get Back To You In 24/48 Hours</div>';

View

Code:
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
&lt;?php if (isset ($message_success)) : echo $message_success; endif; ?&gt;
</div>
</div>

But people say. it is best to make a data variable for it would you know what I would need to do?

Also on another topic. when my validation kicks in the content that was entered correct goes ways and have to re enter it I only want to be able to re enter the validation errors if any comes up.




Theme © iAndrew 2016 - Forum software by © MyBB