Welcome Guest, Not a member yet? Register   Sign In
Best way to pull off a "success" message?
#1

[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!".
#2

[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
#3

[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.
#4

[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.
#5

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

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

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

[eluser]cinewbie81[/eluser]
Check http://www.derekallard.com/blog/post/enh...n-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
#9

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB