Hi,
I am looking for an elegant way to validate some json-encoded values coming form a post. I consider
valid_json helper function merely a first stage validation, to let me throw away syntactically incorrect input. What I would like to do is validate all the values in a resulting array after json_decode just as if they were posted without json. For this I am trying to implement a custom helper function to further validate the input, but i can't seem to pass an array as an argument to it. The array would need to hold further validation rules concordant with CI4 validation rule syntax, dot matrix syntax included. Has anyone got an idea other than adding secondary validation in the relevent controller's method?
Secondly, even if I pass an json-encoded argument only to decode into an array, how do you request a validator run from inside of a helper function not having access to class pointer?
For now I managed to come up with this:
PHP Code:
public $rule = [
'values' => [
'rules' => 'trim|required|valid_json|json_contain_fields[id,name,owner_id]'
]
]
json_contain_fields being my helper function. It is now limited only to checking if certain keys exist in the array after json_decode.