Get submitted value from form select tag in PHP
Description
The following code shows how to get submitted value from form select tag.
Example
<?php//from w ww . j a v a 2 s .c o m
if ( isset( $_POST["submitButton"] ) ) {
switch ( $_POST["store"] ) {
case ".com":
header( "Location: http://www.amazon.com/" );
break;
case ".ca":
header( "Location: http://www.amazon.ca/" );
break;
case ".co.uk":
header( "Location: http://www.amazon.co.uk/" );
break;
}
} else {
displayForm();
}
function displayForm() {
?>
<!DOCTYPE html>
<html>
<body>
<h1>Amazon Store Selector</h1>
<form action="" method="post">
<div style="width: 35em;">
<label for="store">Choose your Amazon store:</label>
<select name="store" id="store" size="1">
<option value=".com">Amazon.com</option>
<option value=".ca">Amazon.ca</option>
<option value=".co.uk">Amazon.co.uk</option>
</select>
<div style="clear: both;">
<input type="submit" name="submitButton" id="submitButton" value="Visit Store" />
</div>
</div>
</form>
<?php
}
?>
</body>
</html>
The code above generates the following result.