Welcome Guest, Not a member yet? Register   Sign In
Flash var messages not appearing after form submission
#1

[eluser]ajushi[/eluser]
In my code:
Code:
if ($this->form_validation->run())
        {
            // Check if the uploaded file is valid
            if (!$this->upload->do_upload('audio_file'))
            {
                $this->session->set_flashdata('error', '<p class="error-msg">Invalid audio file. Files must be of types MP3, WMV or OGG and less than 15MB.</p>');
            }
}

and on my view:
Code:
&lt;?php echo $this->session->flashdata('error'); ?&gt;

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?
#2

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

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

[eluser]alboyd[/eluser]
Yeh you can do that but that doesn't sound like a good solution Smile (EDIT: I always did it this way with a view_data msg variable or something until I realised I could use callback functions)

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

[eluser]ajushi[/eluser]
Could you post an example alboyd about your suggestion? Even if it's a simple one. I'd appreciate it Smile
#6

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

[eluser]ajushi[/eluser]
Cool! I'll check it out! Thanks alboyd! Smile




Theme © iAndrew 2016 - Forum software by © MyBB