Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

develop12's avatar

Validation array [select option]

Hello! I have the next problem I have previously used the Array Input validation in forms but with text inputs, currently I make the same structure but with select option and for some reason it does not take them into account in the validation, I want to think that it is because the title only says array Input but then I would like to request support to know how I can validate my select option array

<div class="grid grid-cols-6 gap-6">
	<div class="col-span-6 sm:col-span-2">
		<label for="" class="block text-sm font-semibold text-gray-700">Competidor 1</label>
		<select name="competitors[1][name]" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" multiple>
			<option selected disabled>Selecciona una opción</option>
			<option value="competidor1">Competidor 1</option>
			<option value="competidor2">Competidor 2</option>
		</select>
	</div>
	<div class="col-span-6 sm:col-span-2">
		<label for="" class="block text-sm font-semibold text-gray-700">Competidor 2</label>
		<select name="competitors[2][name]" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
			<option selected disabled>Selecciona una opción</option>
			<option value="competidor1">Competidor 1</option>
			<option value="competidor2">Competidor 2</option>
		</select>
	</div>
</div>

Validation code

public function rules()
{
        return [
          'competitors.*.name' => 'required',
		];
}

I wish you can support me, have a nice day

0 likes
2 replies
Snapey's avatar

that seems ok. What are you missing?

develop12's avatar

At this moment @Snapey, for some reason, my validation request does not take into account the array of competitors since, by not selecting an option, it does not indicate that it is mandatory to select an option, that is where I find myself overwhelmed

Please or to participate in this conversation.