php - Make field required only if other field is filled out


I have a form that is a list of products.

ONLY 1 product is required to submit the form.

However, if certain products are selected, a color must be chosen also.

I am having trouble getting the color field required if that specific product is selected.

Here is my HTML code for two of my products.

<input type="checkbox" onClick="return ProductsKeepCount()" name="m13_2" value="BPCK"> B. Polar CoolFit Kit

Must choose color:  
<input type="radio" name="m13_3" value="Khaki"> Khaki 
<input type="radio" name="m13_3" value="Black"> Black

<input type="checkbox" onClick="return ProductsKeepCount()" name="m13_4" value="CSZSV"> C. Steele Zipper Style Vest

Must choose color:  
<input type="radio" name="m13_5" value="Blue"> Blue
<input type="radio" name="m13_5" value="Khaki"> Khaki

Here is my PHP code that I want to require the color of the product is checked off.

if ($_POST['m13_2']=="BPCK" && && $_POST["m13_3"] == "") 
Print("You must choose a color for Product B");

Any help would be appreciated!




I had && written twice.

if ($_POST['m13_2']=="BPCK" && $_POST["m13_3"] == "") 
Print("You must choose a color for Product B");

People are also looking for solutions to the problem: php - Laravel framework install failed on xampp


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.