file upload validation |
[eluser]Unknown[/eluser]
I notice that when using rules config file the validation is not workin. To fix it just add the rules parameter in the constructor. Change This Code: function __construct() For this Code: function __construct($rules = array()) Hope this help!
[eluser]nomikos3[/eluser]
Fake $_POST is a bad practice... Like all fakes For validate files you only need to load the upload library and config your preferences (allowed_types, max_size, etc..., see preferences in http://ellislab.com/codeigniter/user-gui...ading.html). and show errors trough a simple message: Code: # in controller: If you need validate others fields add Form_validation and manage errors as usual. Code: # in view:
[eluser]stondin[/eluser]
Its entirely understandable to think that you validate a form and its inputs with the form validation class and you display error from a file upload using file upload class however.... The situation that constantly arises, or at least in my experience, is that you usually have a file upload within a form that may fail validation. If the file uploads correctly, great, but a user causes the validation to fail elsewhere in the form (eg, forgot to add a required title) what happens to the file? The user is presented with an new file input! Is there an easy solution that I'm missing? Currently I store the uploaded file ID somewhere and hang onto it until the form passes all validation. There just seems to be a real disconnect. Thoughts? Alternative solutions?
[eluser]Unknown[/eluser]
Not sure if you found your solution here, but there is no way to re-populate the upload field unfortunately. It's a security measure with all browsers. Imagine what you could access if you "could" re-populate the upload field. You would essentially have access to the entire remote users computer, and could easily change the path during the validation, allowing you to steal any file, or the entire hardrive for that matter. You could try using javascript, jquery, or ajax to validate the field before the submit button would actually submit and refresh your page. That would at least let the person know ahead of time. Hope this helps. I sure spun my wheels on it for a few minutes. ;-) Now I'm just working on validating a combination of upload fields with if statements which is fun. If this one is blank, require the other one, so on and so on.
[eluser]Syed Rakib Al Hasan[/eluser]
here is how I did my validation of the form entries and file entries.... it works pretty well Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |