Flash var messages not appearing after form submission |
[eluser]ajushi[/eluser]
In my code: Code: if ($this->form_validation->run()) and on my view: Code: <?php echo $this->session->flashdata('error'); ?> I tested it out. It used to be a custom $data['error_msg'] and now I'm trying out flashvars. The problem is the error won't display on the view after submitting the from.The error message displays after I do a refresh on the page (F5). Why is it behaving this way?
[eluser]alboyd[/eluser]
Because that's the way it is supposed to behave. flashdata is available on the next page load. You are better off using form validation for what you are trying to achieve (imo). Otherwise you would need to reload the page by putting a redirect(); after you set the flashdata. EDIT: So I see you are putting that into the validation success code. Instead create a callback function in the validation rules section of your form load page.
[eluser]ajushi[/eluser]
I don't use any callback functions. I could create one for that sole purpose though but I don't think that's a good solution. Do you think I'd just stick with putting my messages in $data and displaying them in the page if it exists?
[eluser]alboyd[/eluser]
Yeh you can do that but that doesn't sound like a good solution ![]() Why don't you just create a callback function for this? It's dead simple and it's definitely a good solution. The only way it might not be a good solution (that just occurred to me) is that I wonder if it actually does the upload even if another validation rule for the form fails? The only way the callback function can return true or false is if it actually performs the upload...
[eluser]ajushi[/eluser]
Could you post an example alboyd about your suggestion? Even if it's a simple one. I'd appreciate it ![]()
[eluser]alboyd[/eluser]
Yeh I can but instead I think I should push you towards another thread that I just found. I have just implemented the extended Form_validation library in this thread and it's fantastic. Except I think I might have found a small bug (see my last contribution to the thread). http://ellislab.com/forums/viewthread/123816/ Basically this guy has written an extension for the form_validation library which allows you to specify a rule for example: Code: $this->form_validation->set_rules('userfile', 'Poster Image', 'file_required|xss_clean|file_allowed_type[image]|file_size_max[2000]'); In other words - no callback functions required - the form_validation library now validates the $_FILES to see if the file meets the rules.. Pretty cool!
|
Welcome Guest, Not a member yet? Register Sign In |