Extended form_validation: now with file checking :) |
[eluser]Chicken's Egg[/eluser]
GlennJ, you saved my day! I discovered this evening that a select box which had the rule 'required' was not stopping the form from being submitted when the other input fields were filled in correctly. I felt so happy when I found your solution! But there is one thing I don't understand. Wenn I saw the new code, I was afraid that if I would upload a file other fields would not be validated anymore. But that is certainly not the case. It worked like te charm. But, how come? Below is also some new code. I altered the function file_size_max() once again. The function now watches the server settings too. If the maximum file size the website developer allows, crosses the limits of the server configuration, his value is overwritten by the value given by the server. Code: // FUNCTION: file_size_max
[eluser]devbro[/eluser]
There is an issue here check this link: http://ca3.php.net/manual/en/features.fi...errors.php lookup these: UPLOAD_ERR_INI_SIZE UPLOAD_ERR_FORM_SIZE As you can see if the file size is already violated then the file will not be available. Will it be ok if I use your _let_to_num($v) in the new version of the code?
[eluser]quest13[/eluser]
It seems to solve most of the upload issues in a simple and effective way. Please can you clarify on following points as I am new to php and CI. 1.Should I save this extension of class validation as a separate file in library ? or simply I can paste it on the 'form_validation' library ? 2.In view, we give set_value for text type. How to give set_value for file type ? Is it the same like text type ? I tried it by creating a separate file and included in the library.It didn't work.( I did include that library in controller)and I tried set_value and that too didn't work. Any help in this regard from any one of you is highly appreciated. Thanks in advance.
[eluser]GlennJ[/eluser]
1) You should extend the the class, don't change the CI code as you'll have a nightmare if you want to upgrade to the latest version. 2) You can't set the value of a file field, due to security reasons (e.g. you could set it to a file they didn't specify and grab it from their system!).
[eluser]Chicken's Egg[/eluser]
Quote:Will it be ok if I use your _let_to_num($v) in the new version of the code?Of course, but you might be even more interested in this one: Code: function let_to_bit($sValue) I wrote the function for your extension, so please feel free to use it if you like.
[eluser]devbro[/eluser]
[quote author="quest13" date="1249651776"] 2.In view, we give set_value for text type. How to give set_value for file type ? Is it the same like text type ? [/quote] To approach this and reduce the headache of uploading files on each form_validation failure you can do this: 1. if file had no problem copy it to temp folder and keep the link to it in session. 2. on your form if the link is specified then make the field optional.
[eluser]quest13[/eluser]
I was away from code igniter forum for the past one month as I was busy doing a project in wordpress. I found a tremendous difference between CI and wordpress or any other framework as a matter of fact,in terms of forum response and technical bench strength. The response from CI is just overwhelming.I sometimes wonder whether someone is already started replying my question when I just start typing in the forum ! The response is so quick and so prompt. I have become a die-hard fan of CI now. Thanks once again for my file upload validation query. But I still have one problem.In my view page, I have only "name" and "file" mentioned, not the size. But in file_required function, it checks for the 'size'(===0).It means I have to tell about the size also in my view page as a mandatory requirement ? Thanks
[eluser]GlennJ[/eluser]
The size is handled automatically, all you need is the file field in you view. PHP will then generate a global variable with all the details of the uploaded file(s), 'size' is one of the attributes. See http://us3.php.net/manual/en/reserved.va....files.php for more information.
[eluser]devbro[/eluser]
For Those of you that like this class and are using it I have a news The new version of the code is now completed. you can check it out at: http://devbro.com/testing/ci_form_validation/ I have added a few new rules: file_min_size file_disallowed_type file_image_mindim file_image_maxdim let me know what you think of the new code.
[eluser]Chicken's Egg[/eluser]
Great work Devbro. I'm Looking forward to upgrade to version 2. :p |
Welcome Guest, Not a member yet? Register Sign In |