Support the ongoing development of Laravel.io →
Security Requests Input
Last updated 2 years ago.
0
Solution

Not quite sure, if that will work, because I am beginner and I have not used them myself yet. Anyhow, the Laravel Validation doc states that you can use condtional "required" rules like "required_with", "required_without" etc. http://laravel.com/docs/4.2/validation

I would try something like this:

['field_a' => 'required_without:field_b', 'field_b' => 'required_without:field_a']

which should result in "field a must be present only, if field b is not present" and "field b must be present only, if field a is not".

It still leaves the possibility of filling both fields. Is that a problem for you?

Last updated 9 years ago.
0

goedda said:

Not quite sure, if that will work, because I am beginner and I have not used them myself yet. Anyhow, the Laravel Validation doc states that you can use condtional "required" rules like "required_with", "required_without" etc. http://laravel.com/docs/4.2/validation

I would try something like this:

['field_a' => 'required_without:field_b', 'field_b' => 'required_without:field_a']

which should result in "field a must be present only, if field b is not present" and "field b must be present only, if field a is not".

It still leaves the possibility of filling both fields. Is that a problem for you?

Thanks a bunch, it works perfectly! And the way my application works, choosing a and b is impossible since one is cleared when the other is selected.

Cheers!

0

Well, not to complicate things, but if it is not explicitly forbidden to post field a AND field b, respectively, then someone might use that to his/her advantage. You must ask yourself whether this might pose a problem, if your input contains data for field a and field b. If it does pose a problem, you should check for that too.

I guess, you could simply gather all data and delete either field a or b, if both contained data. That should not be a big problem.

Last updated 9 years ago.
0

goedda said:

Well, not to complicate things, but if it is not explicitly forbidden to post field a AND field b, respectively, then someone might use that to his/her advantage. You must ask yourself whether this might pose a problem, if your input contains data for field a and field b. If it does pose a problem, you should check for that too.

I guess, you could simply gather all data and delete either field a or b, if both contained data. That should not be a big problem.

Well, this is for an admin interface and the worst thing that happens is you get a working entry into the db, but it might not be the intended entry. So sure, if an admin wants to tamper, they can ruin things for themselves, but that's it :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

phroggyy phroggyy Joined 30 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.