CodeIgniter Forums
how extends form validation with custom file check validation? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how extends form validation with custom file check validation? (/showthread.php?tid=74367)



how extends form validation with custom file check validation? - aguileraq - 09-16-2019

Hi, i am trying to create a custom validation to verify the file type and desire, extend the form validation class, but I don't get results ...

my code:

https://gist.github.com/aguileraq/573e34258038c775561dd3db348f30ed

and this is my response:

Code:
{
   "response":{
      "rank":"Campo obligatorio.",
      "name":"Campo obligatorio.",
      "first_lastname":"Campo obligatorio.",
      "second_lastname":"Campo obligatorio.",
      "birthday_day":"Campo obligatorio.",
      "birthday_month":"Campo obligatorio.",
      "birthday_year":"Campo obligatorio.",
      "registration_number":"Campo obligatorio.",
      "rfc":"Campo obligatorio.",
      "discharge_date":"Campo obligatorio.",
      "discharge_place":"Campo obligatorio.",
      "street":"Campo obligatorio.",
      "number":"Campo obligatorio.",
      "between_streets":"Campo obligatorio.",
      "suburb":"Campo obligatorio.",
      "city":"Campo obligatorio.",
      "zipcode":"Campo obligatorio.",
      "municipality":"Campo obligatorio.",
      "phone":"Campo obligatorio."
   },
   "res":"error"
}

All validation return a message but field picture return nothing...

any suggestion? thanks for your help


RE: how extends form validation with custom file check validation? - php_rocs - 09-17-2019

@aguileraq,

What trouble shooting have you done? Have you checked the returned fields in the browser? Have you checked the values obtained by CI prior to validation?


RE: how extends form validation with custom file check validation? - aguileraq - 09-17-2019

Hi @php_rocs



Quote:Have you checked the returned fields in the browser?
yes, i have an ajax response (see the response part in the first post)


Quote:Have you checked the values obtained by CI prior to validation

no, I have not checked that the post returns


RE: how extends form validation with custom file check validation? - jreklund - 09-17-2019

You are trying to access $_FILES['file'] instead of $_FILES['picture']. But just try to return false, to see if it's working or not.

And please remove xss_clean from everywhere, it's not supposed to be used:
https://codeigniter.com/userguide3/installation/upgrade_300.html#step-13-check-for-usage-of-the-xss-clean-form-validation-rule


RE: how extends form validation with custom file check validation? - aguileraq - 09-17-2019

(09-17-2019, 12:03 PM)jreklund Wrote: You are trying to access $_FILES['file'] instead of $_FILES['picture']. But just try to return false, to see if it's working or not.

And please remove xss_clean from everywhere, it's not supposed to be used:
https://codeigniter.com/userguide3/installation/upgrade_300.html#step-13-check-for-usage-of-the-xss-clean-form-validation-rule

Hi @jreklund , thanks for the answer; I already tried to change file by image and I still don't get the validation message, just by returning false

I don't know what else to try Sad


RE: how extends form validation with custom file check validation? - php_rocs - 09-17-2019

@aguileraq,

Try a var_dump before validation to see what the array values are?


RE: how extends form validation with custom file check validation? - aguileraq - 09-17-2019

(09-17-2019, 08:22 PM)php_rocs Wrote: @aguileraq,

Try a var_dump before validation to see what the array values are?

Hi again, i make two tests.

I did 2 tests, the first one:

PHP Code:
public function createPost(){
        var_dump($_REQUEST);
        die;
....


and the response:

Code:
C:\wamp64\www\acv1\application\controllers\Military.php:39:
array (size=25)
  'service' => string '' (length=0)
  'speciality' => string '' (length=0)
  'subspeciality' => string '' (length=0)
  'course' => string '' (length=0)
  'name' => string '' (length=0)
  'first_lastname' => string '' (length=0)
  'second_lastname' => string '' (length=0)
  'month' => string '' (length=0)
  'day' => string '' (length=0)
  'year' => string '' (length=0)
  'registration_number' => string '' (length=0)
  'rfc' => string '' (length=0)
  'discharge_date' => string '' (length=0)
  'discharge_place' => string '' (length=0)
  'street' => string '' (length=0)
  'number' => string '' (length=0)
  'between_streets' => string '' (length=0)
  'suburb' => string '' (length=0)
  'city' => string '' (length=0)
  'zipcode' => string '' (length=0)
  'municipality' => string '' (length=0)
  'phone' => string '' (length=0)
  'mobile' => string '' (length=0)
  'additional_phone' => string '' (length=0)
  'admission_date' => string '' (length=0)

the last test:

PHP Code:
public function createPost(){
        var_dump($_FILES["picture"]);
        die;
...



and the response: empty input file:
Code:
C:\wamp64\www\acv1\application\controllers\Military.php:39:
array (size=5)
  'name' => string '' (length=0)
  'type' => string '' (length=0)
  'tmp_name' => string '' (length=0)
  'error' => int 4
  'size' => int 0

with a file:

Code:
C:\wamp64\www\acv1\application\controllers\Military.php:39:
array (size=5)
  'name' => string 'all.min.css' (length=11)
  'type' => string 'text/css' (length=8)
  'tmp_name' => string 'C:\wamp64\tmp\php6E4D.tmp' (length=25)
  'error' => int 0
  'size' => int 55967



RE: how extends form validation with custom file check validation? - php_rocs - 09-19-2019

@aguileraq,

I don't see the field picture in the array. Should it be there?


RE: how extends form validation with custom file check validation? - aguileraq - 09-20-2019

(09-19-2019, 06:37 AM)php_rocs Wrote: @aguileraq,

I don't see the field picture in the array.  Should it be there?

Hi @php_rocs, answering your question.. yes, but thats the problem... for some reason when put this funcion on extended library (form_validation) nothing happend.. but when the function is in the same controller, i call that function with the prefix "callback_".. and works..

Undecided


RE: how extends form validation with custom file check validation? - php_rocs - 09-20-2019

@aguileraq,

Here is a suggestion to follow for creating a callback function...https://codeigniter.com/user_guide/libraries/form_validation.html?highlight=callback#callbacks-your-own-validation-methods