CodeIgniter Forums
Best way to pull off a "success" message? - 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: Best way to pull off a "success" message? (/showthread.php?tid=5438)

Pages: 1 2


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]Shpigford[/eluser]
I see how to implement error messages with forms but what about "success" messages? I don't want to always send the user to a new page...rather just show a simple "XYZ has been updated!".


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]ekeretex[/eluser]
In the controller, pass the success message to the view if validation passes:
Code:
$this->data['success'] = 'Your blah has uploaded';
In the view:
Code:
<?php if (!empty($success)) : ?>

<p class="success">&lt;?php echo $success; ?&gt;</p>

&lt;?php endif; ?&gt;

Hope that helps


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]Shpigford[/eluser]
I forgot to mention that I do a redirect() after the form is processed (to avoid somehow hitting refresh and resending the form.

So unless I'm mistaken, I can't really pass that. To my knowledge it'd need to be more of a setup with a unique session that is created on success and then cleared once it's displayed.

I could probably create a helper to do this but wasn't sure if something already existed.


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]ekeretex[/eluser]
Ideally (even for displaying error message) you should not show your status messages on the same page as your post.
This elimates the danger of double submission and the alert box that pops up if a user refreshes a page after doing a post.
Details here and here.

I personally use the OBSession session library, pass all status messages (errors and success) into a flash variable, redirect (to the same page, sometimes) and then display the status messages.

This method ensures the page the user sees is always displayed via a get.


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]ekeretex[/eluser]
I see you actually beat me to that observation


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]Shpigford[/eluser]
Smile I'll check out that session library.


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]ekeretex[/eluser]
Soon to be launched CI 1.6 also includes flash variables. You can grab a copy off SVN.


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]cinewbie81[/eluser]
Check http://www.derekallard.com/blog/post/enhanced-codeigniter-session-library/

U can use the

$this->session->set_flashdata('msg', 'Success');
redirect('user/listing');


Mine is working on local machine, but i dont know why it's not working on the server Sad


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]Shpigford[/eluser]
Yeah, I just updated to the 1.6 build and the flashdata stuff is perfect.


Best way to pull off a "success" message? - El Forum - 01-21-2008

[eluser]cinewbie81[/eluser]
Now my turn to ask the question [insert smiley icon]

Why mine is works on local machine but not on the server ??
any setting i need to be done on the server side as both of them using the same source code