rules multiple uploads |
Code: <input name='foto[]' type='file' multiple /> How to specify rules for multiple downloads? PHP Code: 'foto' => ['label' => 'Images', 'rules' => 'uploaded[foto]|mime_in[foto,image/png,image/jpeg]']
Will someone tell me? Is rule validation supported if the field is an array, for example:
Code: <input name="id_cat[]" />
Hello !
I think you skipped this page of the documentation ![]() [/url] [url=https://codeigniter4.github.io/userguide/libraries/uploaded_files.html#multiple-files]https://codeigniter4.github.io/userguide/libraries/uploaded_files.html#multiple-files But maybe it's because this section is not appearing in the documentation's summary at the top of the page. It's a "bug" ![]() Have a good day !
(01-11-2020, 01:53 AM)littlej Wrote: Hello !To download files, it works, with the rest of the data - no ...
Hello !
I am going to need some more clarifications :-) Your original question is "How to specify rules for multiple uploads ?". The page I gave you is describing exactly this: 1/ Getting ALL files: $imagefile = $this->request->getFiles() 2/ Looping on files: foreach($imagefile['images'] as $img) 3/ Validating and "saving" the file: if ($img->isValid() && ! $img->hasMoved()) "isValid" refers to this: https://codeigniter4.github.io/userguide...ify-a-file And you could apply your own custom rules. Juste check whatever you need to check on "$img". So... What do you mean when you say "with the rest of the data - no". Which data ? A file ? Do you have code to show in order to help me understand ? Thank you ;-)
Sorry, everything is in order with the first question, and having studied the code, I realized that there is no verification of arrays of ordinary data fields (example in # 2), which is sad (. I’ll have to finish it by myself.
Validation of arrays with "ordinary data fields": https://codeigniter4.github.io/userguide...are-arrays
(01-12-2020, 07:42 AM)littlej Wrote: Validation of arrays with "ordinary data fields": https://codeigniter4.github.io/userguide...are-arraysYes, thanks, I read it. Here, just show me how to check for int data such data from the form: Code: <input name="id_cat[]" /> PHP Code: $this->validate([ PHP Code: /** There will be an error, because the method waits for the string, and the array arrives ... Error: Argument 1 passed to CodeIgniter\\Validation\\FormatRules::numeric() must be of the type string or null, array given, called in D:\\OpenServer\\OSPanel\\domains\\ci4.ru\\system\\Validation\\Validation.php on line 279
The form (view)
Code: <form method="post"> The validation (controller) PHP Code: $rules = [ Could this be a solution ?
Quote:Could this be a solution ? I tried it now, the error also crashes ... |
Welcome Guest, Not a member yet? Register Sign In |