PHP-Foundation
PHP-Foundation copied to clipboard
Validate input serialize multiple value
Hi, How I should validate a serialized multiple value (multiple[]=1st, multiple[]=2nd) because if I use
$app->input()->post('multiple', TYPE_RAW);
return null.
Thanks.
This is indeed not available yet, but you’re right in that we should definitely add it.
By the way, TYPE_RAW is probably not what you want. So you may want TYPE_STRING or something else instead.
Could you try something like the following?
// $key = 'multiple';
// $type = \TYPE_STRING;
$data = !empty($_POST[$key]) && \is_array($_POST[$key]) ? $_POST[$key] : [];
foreach ($data as $key => $value) {
$data[$key] = $app->input()->value($value, $type);
}
Does that work? If it does, we could certainly implement it as a convenient wrapper so that you would be able to call
$app->input()->postArray('multiple', TYPE_STRING);
in the future.
Thanks, it was just a segnalation but was not sure if I was missed something.
It's not so important there are different turnaround for fix but just because your framework is really well done should to be implemented.
Good this
$app->input()->postArray('multiple', TYPE_STRING);
Thanks again I don't know if you wanna this post as reminder by the way for me can be closed.
Thanks!
Let’s leave this open here until it’s implemented.
Please try the code above and see if it works for your use case when you find the time.