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

Validate data in rest api

Hi How i can validate post/put data in rest api?

Hi, You can validate your data via forms



25.0k
edited Nov '14

i use angularjs, all data send in json format

how check and validate it?



7.9k

you can decode your json into php array.

for example if here is your validation code

$validation->add('name', new PresenceOf(array(
    'message' => 'The name is required'
)));

then your array must be formatted like this

[
    "email" => "[email protected]"]
]


25.0k
edited Nov '14

How i can use many filters for one json value in controller?

example: $phone = " 123<a>456</a>789";

need use filters: striptags, trim

Use validation component

you can decode your json into php array.

for example if here is your validation code

$validation->add('name', new PresenceOf(array(
   'message' => 'The name is required'
)));

then your array must be formatted like this

[
  "email" => "[email protected]"]
]

Hi. sorry I saw that but I am confused how to start with this code. from where Class PresenceOf().

and how to start with API for this validation