![]() |
I'm not able to validate the array of items that I'm passing via json.
Here's how I'm trying: Rules: PHP Code: public $createTransaction = [ JSON: Code: { I pass the json normally. PHP Code: $json = $this->request->getJSON(true); It does not validate only on array items, for example: in the "id" field, if only one field is correct, it passes validation.
Which veraion you are using
I dont have any problem with json request
Enlightenment Is Freedom
I use the current version 4.1.3.Below is a json that is wrong, but passes validation:
{ "api_key": "syPK1zJAUT", "date_expire": "2021-07-27 00:01:00", "customer": { "name": "Reinaldo", "email": "[email protected]", "external_id": "1" }, "items": [ { "id": "1", "name": "Notebook Dell", "description": "Notebook Dell 4GB", "value": "3000" }, { "ii": "2", "name": "Notebook Samsung", "description": "Notebook Samsung 4GB", "value": "3000" } ], "amount": "6000" } Note that the second product id is wrong, but in validation it does not affect any
You need to json_decode the json array to an associated array first.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(07-27-2021, 05:03 AM)InsiteFX Wrote: You need to json_decode the json array to an associated array first.He get the data with getJSON(), so no need to call json_decode, it’s already done by getJSON(). PHP Code: $json = $this->request->getJSON(true); PHP Code: public function getJSON(bool $assoc = false, int $depth = 512, int $options = 0) |
Welcome Guest, Not a member yet? Register Sign In |