CodeIgniter Forums
set_message Dysplay - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: set_message Dysplay (/showthread.php?tid=51656)



set_message Dysplay - El Forum - 05-12-2012

[eluser]Gabi3xz[/eluser]
Example
have code
Code:
$this->load->library('form_validation');

if ( $res !== false ) {
    $_SESSION['username'] = $this->input->post('email_address');
    //insert here set_message "Success"
    $this->form_validation->set_message('success_login', 'Login success');

            } else {
    echo "Incorrect";
   }
used
Code:
$this->form_validation->set_message('success_login', 'Login success');
and added $lang['success_login'] = "Success login."; in form validation lang and does not display message.
What is not correct?


set_message Dysplay - El Forum - 05-12-2012

[eluser]vrencianz[/eluser]
The set_message() function is used to display error messages (See http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors for setails).

To display a success message

1) You can use the success page

or:

2) Create two helper functions (in a file helpers/utils_helper.php, for example)

Code:
/**
* Sets a feedback message as flashdata
* @param string $feedback
*/
function set_feedback($feedback)
{
$CI =& get_instance();

$CI->session->set_flashdata('feedback', $feedback);
}

/**
* Gets the feedback data set by set_feedback($feedback)
* @return the feedback message or FALSE if it is not set
*/
function feedback()
{
$CI =& get_instance();

return $CI->session->flashdata('feedback');
}

3) On success call <b>set_feedback('Login success');</b>

4) Somewhere in your view insert

Code:
&lt;?php if($feedback): ?&gt;
<div id="feedback">
  &lt;?=$feedback?&gt;
</div>
&lt;?php endif?&gt;

5) load your view

Code:
$this->load->helper('utils');
...
$data['feedback'] = feedback();

$this->load->view('your_view', $data);

I hope this helps.


set_message Dysplay - El Forum - 05-12-2012

[eluser]Gabi3xz[/eluser]
Thanks, now I understand