Avatar of Bruce Gust
Bruce Gust
Flag for United States of America

asked on 

How can I see if at least one of these checboxes has been checked?

Here's my Contact form:

checkbox
I want to ensure my user has selected at least one of the checkboxes. I know how to do it in JQuery, but I want to make use of the:

@if($errors->any())
						<div class="alert alert-danger">
							<ul>
								@foreach($errors->all() as $error)
									<li>{{ $error }} </li>
								@endforeach
							</ul>
						</div>
					@endif

Open in new window


...section of my blade, as opposed to a traditional "alert" box.

How?

In the past, I've done something like this:

$data = request() -> validate([
			'name'=> 'required',
			'email' => 'required',
			'occupation' => 'required',
			'address_1' => 'required',
			'city' => 'required',
			'state' => 'required',
			'postal_code' => 'required',
			'country' => 'required',
			'phone' => 'required', 
			'comments' => 'required'
		]);

Open in new window


...which works fine, as far as validating the input fields, but it doesn't give me the freedom to check the boxes like I need to as far as ensuring at least one has been checked.

How can I pull this off?
LaravelPHP

Avatar of undefined
Last Comment
lenamtl

8/22/2022 - Mon