Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate input serialize multiple value #32

Open
daebak74 opened this issue Mar 3, 2020 · 3 comments
Open

Validate input serialize multiple value #32

daebak74 opened this issue Mar 3, 2020 · 3 comments

Comments

@daebak74
Copy link

daebak74 commented Mar 3, 2020

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.

@ocram
Copy link
Contributor

ocram commented Mar 5, 2020

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.

@daebak74
Copy link
Author

daebak74 commented Mar 5, 2020

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.

@ocram
Copy link
Contributor

ocram commented Mar 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants