How can I show success message (not alert box) in home page after successful signup


How can I show success message (not alert box) in home page after successful signup



How can I show a success message (not alert box) in home page after a successful signup?



This is my controller function.


public function reg()
{
$data['baseurl'] = base_url();
$baseurl = base_url();
$this->load->model('Regdatabase');
$this->form_validation->set_rules('firstname', 'First Name', 'required');
$this->form_validation->set_rules('lastname', 'Last Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|matches[cpassword]|md5');
$userdata['id'] = Null;
$userdata['firstname'] = $this->input->post('firstname');
$userdata['lastname'] = $this->input->post('lastname');
$userdata['email'] = $this->input->post('email');
$userdata['password'] = $this->input->post('password');
$userdata['status'] = "1";
$this->Regdatabase->DataInsert($userdata);
// INSERT DATA INTO TABLE
redirect($baseurl.'register');
}




4 Answers
4



set your success message in session flash message and then show in home page as you want.


$this->session->set_flashdata('success_msg', 'success');



to get success message


echo $this->session->flashdata('success_msg');



Set flash message in your controller, then redirect to home page after successfull registration.



See below example to get clear idea..


function index()
{
$this->load->library('form_validation'); // Load validation library.
$this->load->model('register_model');
$data['msg']=NULL; // Declare msg as NULL.

// On form submit.
if(isset($_POST['add']))
{
// Input fields validations
$this->form_validation->set_rules('name', 'Name', 'trim|required|max_length[100]|min_length[3]');

if ($this->form_validation->run() === TRUE)
{
$name=$this->input->post('name');

$values=array('name' => $name);

$result=$this->register_model->my_insert($values,'users'); // Insert user into database.

if($result_id)
$data['msg']='1';
else
$data['msg']='2';
}
}
$this->load->view('register', $data);

}



flash data used to showing success messages in codeigniter


$this->session->set_flashdata('item', 'value');

You can also pass an array to set_flashdata(), in the same manner as set_userdata().

To read a flashdata variable:

$this->session->flashdata('item');



http://ellislab.com/codeigniter%20/user-guide/libraries/sessions.html



Use parameter to redirect to home page with the success message.



redirect($baseurl.'home/index/success');


redirect($baseurl.'home/index/success');



Get parameter on home and show message according to that.



$msg=$this->uri->segment(3);


$msg=$this->uri->segment(3);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails