Validating Drop Down Menus Form Input

Problem:- Validating Drop Down Menus Form Input

If you want to make sure that your user selects a valid choice from a drop-down menu.


<form method="POST">
	<select name="food">
		<option value="eggs">Eggs</option>
		<option value="Toast">Toast</option>
		<option value="Coffee">Coffee</option>
		<option value="Salad">Salad</option>
	<input type="submit" name="">

$best_choice = array('eggs', 'Toast', 'Coffee');
if (!in_array($_POST['food'], $best_choice)) {
	echo "You must select a vaild choice";
	echo "Your choice is {$_POST['food']}";



Be the first to comment

Leave a Reply

Your email address will not be published.