Input = file validation on multipart form |
[eluser]Linderman[/eluser]
Hell o! So, the situation is like this: View: Code: <?php echo form_open_multipart('admin/infopages/info'); ?> i am using multipart form! in controller i am trying to say that input type='file' name='thumbnail' is required Controller: Code: $this->load->helper(array('form', 'url')); The problem is when i CHOOSE image and click the submit button CI always says "The Image field is required." AND I AM SHURE ITS NOT EMPTY. Why is that? When i use normal form NOT MULTIPART its ok , CI gives the message only when i really didnt choose a file to upload (normal). But when i use multipart form CI blows this message always no matter the field is empty or not ... Please, Help guys!
[eluser]steelaz[/eluser]
I don't think you can validate file input with form_validation library, it checks $_POST array whereas uploaded file information is located in $_FILES array. You can use file upload library to check if file was uploaded or try JavaScript to validate it.
[eluser]Aken[/eluser]
Create your own callback rule during forum validation, and use it to check the relevant file data. http://ellislab.com/codeigniter/user-gui...#callbacks
[eluser]$ilovephp[/eluser]
forget form validation class when you are only trying to say that a specific field is required if you are using multipart form. you can actually validate that using: Code: if($this->input->post('field_name')!=FALSE) I opt to use this for one reason: Why load an entire class (Form Validation Class) when you can do it without much codes? I suggest you use Form Validation Class when you have multiple fields aside from that of multipart form
[eluser]Linderman[/eluser]
Hello! I validate only 1 fields because of the example. In my life project , the form is big and the file input is required. The question is not why i validate only 1 field using the corresponding class , the question is how to validate file input using normal way? [quote author="steelaz" date="1272150655"]I don't think you can validate file input with form_validation library, it checks $_POST array whereas uploaded file information is located in $_FILES array. You can use file upload library to check if file was uploaded or try JavaScript to validate it.[/quote] yes this is right [quote author="Aken" date="1272246954"]Create your own callback rule during forum validation, and use it to check the relevant file data. http://ellislab.com/codeigniter/user-gui...#callbacks[/quote] and yes , this will do the thing Thank You guys for the answers, it helps a lot!
[eluser]Unknown[/eluser]
Hello, here is my solution for file field validation : In Form_validation.php file, add this in the function run() Code: function run($group = '') Then you can create your own rule, extending the form validation class, for exemple : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); It work good for me. Bye |
Welcome Guest, Not a member yet? Register Sign In |