Solved

drop down boxes and forms

Posted on 2012-04-04
12
234 Views
Last Modified: 2012-07-10
What do I need to change to get this code to work?

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>

Open in new window


welcomeCar.php

Welcome <?php echo $_POST["1"]; ?>!<br />
Welcome <?php echo $_POST["2"]; ?>!<br />
Welcome <?php echo $_POST["3"]; ?>!<br />

Open in new window

0
Comment
Question by:NewWebDesigner
  • 2
  • 2
  • 2
  • +2
12 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 200 total points
ID: 37808865
???
what do you want to happen?
Please articulate a proper question.

(I guess you might want to name the select, not the options like this:

<select name="1">

...but I'm just guessing)
0
 

Author Comment

by:NewWebDesigner
ID: 37808903
Sorry for the unclear question.  This is what I want to happen: A user selects an option from each drop down box. When they click submit, the choices are submitted to the welcomeCar.php page where the choices the user made are printed.  the wecomeCar.php code should be:

Welcome <?php echo $_POST["1"]; ?>!<br />
Welcome <?php echo $_POST["2"]; ?>!<br />

Open in new window

0
 
LVL 7

Assisted Solution

by:designatedinitializer
designatedinitializer earned 200 total points
ID: 37809106
that's what I thought,
You have to name the <select> element, like I said.
0
 
LVL 4

Assisted Solution

by:TechHelpr08210
TechHelpr08210 earned 300 total points
ID: 37809262
Here you go...

This is corrected and should run now for whatever your trying to do.

Page1.html - Corrected

 <!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>Page 1</title>
</head>

<body>
 <form action="welcomeCar.php" method="post">
   <select name="car1">
    <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 name="car2">
    <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>
 

Open in new window




welcomeCar.php - Corrected

<!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>welcomeCar.php</title>
</head>

<body>
Welcome <?php echo $_POST["car1"]; ?>!<br />
Welcome <?php echo $_POST["car2"]; ?>!<br />

</body>
</html>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:Atique Ansari
ID: 37809541
Please find the attached files.

Let me know if you need more help.

Page1.html

welcomeCar.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37809902
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...
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37809936
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
<?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;

Open in new window

0
 
LVL 4

Expert Comment

by:TechHelpr08210
ID: 38156467
Agreed, that sounds like a fine solution to me as well.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now