validating a required file upload field |
[eluser]stef25[/eluser]
is it possible to validate a file upload field using the same "required" parameter as for text fields and textareas? when i select a file for upload, i still get a message back saying this field is required, while it shouldn't. the validation on other fields in the same form work fine (required and valid email) in what way does a file upload file differ from a text field? or do i need to use the file upload class for validation? i know php has error codes specifically for file upload fields that could be checked for using the file upload class. or am i missing something? thx, stef
[eluser]pistolPete[/eluser]
[quote author="stef25" date="1239130812"]in what way does a file upload file differ from a text field?[/quote] Text fields are saved in the $_POST array while file uploads use the $_FILES array. Please have a look at - http://ellislab.com/forums/viewthread/106717/ - http://ellislab.com/forums/viewreply/538506/
[eluser]stef25[/eluser]
hi pistolPete, that makes sense of course. i setup my validation like this Code: if($this->form_validation->run('admin/index') == FALSE) { the i have in config/form_validation.php all the rules. for the image upload field i have Code: array( and a callback function: Code: function _do_upload($file) { when the form is submitted i get a blank page, meaning the callback function gets called but the $file variable is empty. how can i pass the value from my validation file in the config folder back to my callback? hope this makes sense ... thanks
[eluser]stef25[/eluser]
sorry, scratch that ... im now getting "you didnt select a file for upload". this is coming from the CI Upload.php file. so the function gets called, but why would it still think i didnt select a file if i did?
[eluser]stuffradio[/eluser]
Make sure your file field is the correct value. There is a default value that you need to use unless you set your own. I think you have to set that field as Code: userfile |
Welcome Guest, Not a member yet? Register Sign In |