NewWebDesigner
asked on
drop down boxes and forms
What do I need to change to get this code to work?
page1.html
welcomeCar.php
page1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="welcomeCar.php" method="post">
<select>
<option value="volvo" name"1">Volvo</option>
<option value="saab" name="2">Saab</option>
<option value="mercedes"name="3">Mercedes</option>
<option value="audi" name="4">Audi</option>
</select>
<select>
<option value="volvo" name="5">Volvo</option>
<option value="saab" name="6">Saab</option>
<option value="mercedes" name="7">Mercedes</option>
<option value="audi" name="8">Audi</option>
</select>
<input type="submit" />
</form>
</body>
</html>
welcomeCar.php
Welcome <?php echo $_POST["1"]; ?>!<br />
Welcome <?php echo $_POST["2"]; ?>!<br />
Welcome <?php echo $_POST["3"]; ?>!<br />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This looks a lot like another question I've see this morning. Everybody must be doing the same exercise ;-)
Unnamed input tags are simply absent from the request. If you want to see the client input, you must give the <input> or <select> tags a name attribute. I'll show you a code example in a moment...
Unnamed input tags are simply absent from the request. If you want to see the client input, you must give the <input> or <select> tags a name attribute. I'll show you a code example in a moment...
This is a typical design pattern for drop-down select lists. A NULL choice is offered and the client is asked to choose from a list. You can try running this on my server to see what happens. Please see:
http://www.laprbass.com/RAY_temp_newwebdesigner.php
http://www.laprbass.com/RAY_temp_newwebdesigner.php
<?php // RAY_temp_newwebdesigner.php
error_reporting(E_ALL);
if (!empty($_POST))
{
// SHOW THE CONTENTS OF THE POST ARRAY
echo "<pre>";
var_dump($_POST);
echo "</pre>";
echo PHP_EOL;
}
// CREATE THE HTML USING HEREDOC NOTATION
$html = <<<HTML
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="iso-8859-1" />
<title>Form Demonstration</title>
</head>
<body>
<form method="post">
<select name="CAR_ONE">
<option value="" selected>Please Choose A Car</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<select name="CAR_TWO">
<option value="" selected>Please Choose Another Car</option>
<option value="ford" >Ford</option>
<option value="chevrolet" >Chevy</option>
<option value="chrysler" >Chrysler</option>
<option value="bmw" >Bimmer</option>
</select>
<input type="submit" />
</form>
</body>
</html>
HTML;
echo $html;
Agreed, that sounds like a fine solution to me as well.
ASKER
Open in new window