We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Filter / sanitize array data from $_POST

Hello,

To filter a something from $_POST _in phalcon , we use :

         'unit' => $this->request->getPost('unit', 'int').

However how to do deal if I have "unit" variable from $_POST is array ie.

   unit = aray (
            0 => 5,
            1 => 9,
            2 => 18,
            3 => 2
            );


93.7k
Accepted
answer
edited Jul '18

It works for array values also. Just tested myself.

Without sanitize $this->request->getPost('asd')

Array
(
    [0] => asd___1
    [1] => asd___5
    [2] => asd___8
)

With sanitize $this->request->getPost('asd', 'int')

Array
(
    [0] => 1
    [1] => 5
    [2] => 8
)


8.8k

Thanks for confirmation, much appreciated.