Flash Data Without Redirect |
[eluser]RaGe10940[/eluser]
I am trying to send messages back to the users if a account does not exist. I have achieved this, however the data that the user typed in is gone and I spoke with the clients and they explicitly do not want that. They want their information they typed in to save and with the code below : Code: $this->session->set_flashdata('emailview', 'Student Does Not Exist'); it does not work... I have tried this : Code: $this->session->set_flashdata('emailview', 'Student Does Not Exist'); and that works only after I hit submit again (the next hop). this is the code for emailview(); Code: function emailview() { So pretty much : 1) I need the flash data to be sent back with an error if the account does not exist. 2) I need the values the user inputted to not be reset Is this possible?
[eluser]boltsabre[/eluser]
Why don't you just use a form normally? Basically you'd create a callback validation function function, which checks if the user exists, and if they don't display your validation message. By using the inbuilt codeigniter form functions you can display your validation messge instead of trying to do it with flashsdata, and you can also populate the form data back into the inputs easily using the set_value() function. http://ellislab.com/codeigniter/user-gui...elper.html
[eluser]RaGe10940[/eluser]
I'm not quite following you boltsabre this is my code : Code: <?php echo validation_errors('<p class="error">'); ?> what is it that you are trying to relay to me? Thanks,
[eluser]Otemu[/eluser]
Hi, Basically boltsabre is saying that you should use Codeigniter Validation class Provide the user with a form, when a user submits you can run a callback function(example in link), this would check if the user account exists, if it doesn't you can repopulate the form with the class. Saves you using flashdata and writing code for a feature that is already built within the frame work. Hope that more clearer for you
[eluser]boltsabre[/eluser]
In a simplistic overview of how userdata/flashdata and the global $_POST array works is: - To display a newly created userdata/flashdata variable you have to use redirect(). - If you do this, your $_POST array gets emptied because well... there is nothing posted anymore, you've simple redirected them to a new script, which executes, thus the user hasn't had a chance to populate anything into $_POST. So what you're trying to do, which is set & display a flashdata variable AND preserve the data inside $_POST, are at conflict with the above 2 points and cannot be done without some trickery. The easiest way, and the path with the least resistance or chance of bugs, or data being lost, is to instead of using flashdata for this "Student Does Not Exist" validation check is to create a validation callback function. I assume you are currently doing something like this??? - User submits form - You validate it - If errors are found you redisplay the form, with the users input still displayed in the inputs, and display the validation messages. Else - Validation passed, now you do your model call to check if the student exists. If they don't exist you're trying to display the flash message with redirect() AND re-populate the form the the previous user input. If so, don't... use a callback function. It's in the link I first posted. Are you checking the email address for if the student exists? If so, attach the callback to the email validation rules in your controller.
[eluser]RaGe10940[/eluser]
Great community support I swear... anywhos I got it situated and you guys gave me the idea... this is how I did it : the error function in my controller : Code: else { view : Code: <?php echo $error ?> works just fine. and now I can keep my input populated. This could be a "hacky" way of doing it but it works. I will take a look at the "other/right" way of doing it. Again thank you to the both of you!
[eluser]RaGe10940[/eluser]
And no, I am using the Student ID, Student First, and Last, once the email is pulled from the DB, I decode the email (I use AES encrypt for all emails) and then I use the email(s) that I decoded and then just have the $this->email->to($uncryptedemails); works like a charm Again thank you to the both of you, this is a great community I must say.
[eluser]boltsabre[/eluser]
No worries, glad you got it sorted out, but I'd certainly brush up on both "extending the validation library" and "custom callback functions" for form validation, you'll need it as soon as you need a form that can handle more than the basics. And yes, it is a pretty great forum! One of the (many) reasons that I like... no, love... using CI!!! |
Welcome Guest, Not a member yet? Register Sign In |