Welcome Guest, Not a member yet? Register   Sign In
how extends form validation with custom file check validation?
#1

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/573e34...db348f30ed

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
Reply
#2

@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?
Reply
#3

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
Reply
#4

(This post was last modified: 09-17-2019, 12:03 PM by jreklund.)

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/insta...ation-rule
Reply
#5

(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/insta...ation-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
Reply
#6

@aguileraq,

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

(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
Reply
#8

@aguileraq,

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

(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
Reply
#10

@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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB