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");
exit();
}
Any help would be appreciated!
Answer
Solution:
I had && written twice.