susanBuck / e15-spring22

0 stars 0 forks source link

Validation for Image Upload and Checkbox Array in Form #72

Closed luannebe closed 2 years ago

luannebe commented 2 years ago

Hi, I am attempting to validate that at least one checkbox is selected, and that an upload file does not exceed a maximum size. All of the validation rules below work as expected, except the ones for 'categories' (an array of checkboxes) and 'filename' (an image file to be uploaded). Any thoughts would be much appreciated!

    public function store(Request $request) {
        $request->validate([
            'date_observed' => 'required|date',
            'street_number' => 'required|max:255',
            'street_name' => 'required|max:255',

            'categories' => 'array|min:1',
            'filename' => 'mimes:jpeg,bmp,png|size:1000',

            'observer_first_name' => 'required|max:255',
            'observer_last_name' => 'required|max:255',
            'observer_email' => 'required|email',
        ]);
susanBuck commented 2 years ago

Hi @luannebe - FYI Looking at this now and will reply shortly.

susanBuck commented 2 years ago

For the checkbox you can use the validation rule required to make sure at least one is checked.

I tested the validation you used for files and it worked on my end. Looking closer at your view I'm not seeing an error field view for the file field - perhaps that's the issue? Ref: https://github.com/luannebe/e15/blob/main/p3/resources/views/reporter/create.blade.php#L84

luannebe commented 2 years ago

Hi, Thank you! I think figured out the image validation.

On May 10, 2022, at 4:19 PM, Susan Buck @.***> wrote:

For the checkbox you can use the validation rule required to make sure at least one is checked.

I tested the validation you used for files and it worked on my end. Looking closer at your view I'm not seeing an error field view for the file field - perhaps that's the issue? Ref: https://github.com/luannebe/e15/blob/main/p3/resources/views/reporter/create.blade.php#L84 https://github.com/luannebe/e15/blob/main/p3/resources/views/reporter/create.blade.php#L84 — Reply to this email directly, view it on GitHub https://github.com/susanBuck/e15-spring22/issues/72#issuecomment-1122821703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVCIMRMVTY4LJAQN33WRO3VJLADRANCNFSM5VSEMGVA. You are receiving this because you were mentioned.