Extended form_validation: now with file checking :) |
[eluser]nkm82[/eluser]
[quote author="djenniex" date="1258499205"]Is xxs_clean a callback function? Or did you mean to type xss_clean? Also, I did use version 2.1. I've modified it a little bit, so that the function names were clear, removed a couple that were unnecessary, fixed some code that was a bit redundant and made some changes so that they conform more to the CodeIgniter Upload class. I've posted the code, here are the links: Test Controller Test View Custom Form_validation class[/quote] Thanks djenniex, neat code. By the way, it was still failing when no file specified, so I made a little modification to fix it. Now, if no file is specified but the field is not required, no error is thrown and the validation continues. Note: The following code it's for djenniex's version. Code: // It's a file, so process it as a file
[eluser]bradleyg[/eluser]
[quote author="GodsHand" date="1255573721"]Any reason why an error message isn't being displayed when no file is selected? CONTROLLER Code: $this->form_validation->set_rules('userfile','Image','file_required'); Code: <p class="input_text"> I have the same problem as this. It's weird that when you use Code: <?php echo validation_errors(); ?> I used this dirty hack for the time being: Code: <?php if(strpos(validation_errors(), "No file selected") !== false) { echo '<p>No file selected</p>'; } ?> And placed it just underneath Code: <?php echo form_error('userfile') ?>
[eluser]umefarooq[/eluser]
nice extension i really like it but one thing i want to ask can we use it for multiple file upload or array of files uploading. for example Code: <input type="file" name="upload[]" /> will it work for it.
[eluser]Unknown[/eluser]
does anyone know why file_max_size[xxx] isnt working? im using this: Code: $this->form_validation->set_rules('blog_banner', 'Blog Banner', 'file_required|file_allowed_type[image]|file_max_size[100KB]'); everything but file size max works can anybody help me? thanks guys /* update */ found my problem lol using it wrong way around was using file_max_size when its file_size_max lol ![]()
[eluser]Patroklo[/eluser]
First of all, sorry about my bad english, if you have some trouble understanding something that I have said, please ask. Second: Thanks for the library! That's what I was searching for a long time. Now I can use file and form validation in the same controller without problems. I'm making a new version of my web and started using it for the file uploading forms(almost all are images) and for now i dont had any problem until today. The thing is that I have learned that if you make a bmp file in the windows paint and change the extension from bmp to jpg the form_validation thinks that it's a jpg, and it seems that the upload library of codeigniter has the same problem. So I have made a little change in the file_allowed_type function of your library to resolve that. Now instead of using the "type" parameter of the $_FILES variable, I make a new "type" parameter from the uploaded file and, using a MIME function of the upload library I compare the new "type" instead of using file extension comparations. Code: function file_allowed_type($file,$type) Again, if you have some problem understanding me, ask whatever you want.
[eluser]bravonet[/eluser]
[quote author="umefarooq" date="1265711457"]nice extension i really like it but one thing i want to ask can we use it for multiple file upload or array of files uploading. for example Code: <input type="file" name="upload[]" /> will it work for it.[/quote] i had the same problem too.. i had try with few test Code: for ($i=0; $i < $num_files ; $i++) { Code: for ($i=0; $i < $num_files ; $i++) { please point out my mistake. or the library isn't working with multiple upload?
[eluser]AMCerasoli[/eluser]
I'm just starting with CI, I have placed the file MY_Form_validation.php in applications/libraries and then as the user guide says I have just load normally the library Code: $this->load->library('form_validation'); But I'm getting: Fatal error: Call to undefined method CI_Form_validation::CI_Form_validation() in /web/htdocs/www.website.com/home/application/libraries/MY_Form_validation.php on line 50 Am I doing something wrong? thanks. Good extension BTW. :-)
[eluser]TWP Marketing[/eluser]
[quote author="AMCerasoli" date="1347557228"]I'm just starting with CI, I have placed the file MY_Form_validation.php in applications/libraries and then as the user guide says I have just load normally the library Code: $this->load->library('form_validation'); But I'm getting: Fatal error: Call to undefined method CI_Form_validation::CI_Form_validation() in /web/htdocs/www.website.com/home/application/libraries/MY_Form_validation.php on line 50 Am I doing something wrong? thanks. Good extension BTW. :-)[/quote] First, you're responding to a thread that is two years old, which means it was written for an older version of CI. Which version are you using? I assume you are EXTENDING the CI form validation library and not writing your own? Show us your code in MY_Form_validation.php, specifically look at line 50 and at the class declaration at the top of MY_Form_validation.php which should extend CI_Form_validation like this: Code: class MY_Form_validation extends CI_Form_validation { Check your config/config.php and be sure this line is present: Code: ...
[eluser]AMCerasoli[/eluser]
Quote:First, you’re responding to a thread that is two years old Wow... I didn't know... Hahahaha The problem was that I had two files in the server with the same name but with different capitalization (MY_Form.. and MY_form) and was reading the wrong file, the one that I was using to make some test... After that there is no error but the features that it says it has seems to not work at all. It's like there was no extension. Quote:I assume you are EXTENDING the CI form validation library and not writing your own? Yes. I'm not writing my own. Everything was like you said it should (Classes, config) but it doesn't work. I guess this should be added to the official framework, I don't know why this is spitted into a class and a helper... I have solved the problem differently. thanks anyway. Oh and BTW if the forum allow to post something after 2 years is because there shouldn't be no problem with that...
[eluser]TWP Marketing[/eluser]
So you solved your problem? Re the old thread, you can respond unless the site moderators lock it, but the original problem on old thread usually relate to an earlier version, plus the OP may no longer be around to respond with their solution. It's usually better to start a new thread just so people don't have to read the whole thing to get the situation. But it is totally your choice. |
Welcome Guest, Not a member yet? Register Sign In |