i would like to make sure user at least one checkbox and if it select otherand need to make sure to write something in text box
thanks
Code:
<?php
$name = 0;
$cusID=0;
$hobbies =0 ;
if (isset ($_POST["customername"])) {
if($_POST["customername"] == NULL)
$name=1;
if($_POST ["customerid"] == NULL)
$cusID=1;
}
if(!isset($_POST["hobbies"])) {
echo "Please check the box";
}
?>
<h1>Hobby Selection Page<br /></h1>
<form method="post" action="task14.php" id="hobbies" >
<p>
<label for="customername">Customer Name: </label><input type="text" id="customername" name="customername"/><?php if ($name) echo "please enter customer name"?>
<br/>
<label for="customerid">Customer ID Number: </label><input type="text" id="customerid" name="customerid"/><br/>
<?php if($cusID) echo "please enter value in customer id"?>
</p>
<p>Please select between 1 and 3 hobbies from the list below:<br/>
<input type="checkbox" name="hobbies[]" id="cbx1" value="stamp" /><label for="cbx1">Stamp Collecting</label> <br/>
<input type="checkbox" name="hobbies[]" id="cbx2" value="movies" /><label for="cbx2">Movies</label> <br/>
<input type="checkbox" name="hobbies[]" id="cbx3" value="golf" /><label for="cbx3">Golf</label> <br/>
<input type="checkbox" name="hobbies[]" id="cbx4" value="bush" /><label for="cbx4">Bush Walking</label> <br/>
<input type="checkbox" name="hobbies[]" id="cbx5" value="read" /><label for="cbx5">Reading</label> <br/>
<input type="checkbox" name="hobbies[]" id="cbx6" value="music" /><label for="cbx6">Music</label> <br/>
<input type="checkbox" name="hobbies[]" id="cbx7" value="other" /><label for="cbx7">Other</label> <input type="text" name="other" /><br/>
<br/>
<input type="submit" value="Submit Form"/>
<input type="reset" value="Clear Form" />
</p>
</form>
</body>
</html>
Comment