[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why won't my form with drop downs transmit data?  (easy)

Posted on 2012-04-04
6
Medium Priority
?
282 Views
Last Modified: 2012-06-28
Hello.  When a user makes a choice in both select boxes and clicks "submit",  the data should be submitted to welcomeCar.php.  Except that it is not working.  What do I need to change?

choices.php


<!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" name="one">
   <select>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>

   <select>
    <option value="volvo" name="two">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>
   <input type="submit" />
 </form>
</body>
</html>

welcomeCar.php

Welcome <?php echo $_POST["one"]; ?>!<br />
Welcome <?php echo $_POST["two"]; ?>!<br />

Open in new window

0
Comment
Question by:NewWebDesigner
6 Comments
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 37809109
How about
<select name='car1'>
...
<select name='car2'>
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 37809113
In context

<!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" name="one">
   <select name='one'>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>

   <select name='two'>
    <option value="volvo" name="two">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>
   <input type="submit" />
 </form>
</body>
</html>

Open in new window

0
 
LVL 4

Expert Comment

by:TechHelpr08210
ID: 37809236
The above is almost correct except that HTML uses double quotes, not single quotes. :-)



<select name="one">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
 </select>

<select name="two">
    <option value="volvo" name="two">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
</select>

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 37809238
Almost but you had too many 'names'.  Only the <select>s should have names for this purpose.

<!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 name='one'>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>

   <select name='two'>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
   </select>
   <input type="submit" />
 </form>
</body>
</html>

Open in new window

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37809248
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37809782
Any HTML form input tag that omits the name attribute will be omitted from the request to the action script.  You can use var_dump($_REQUEST) to verify this.  In addition to this, which makes some kind of sense to me, there is the issue of checkboxes and radio buttons (and the part about checkboxes and radio buttons does not make sense to me).  There is no default value for these form elements.  An unfired checkbox is simply absent from the request, as if it had not been given a name!  So if you have a named input type=text you've got something in the request, even if it is only an empty string.  But with input type=checkbox you might have something useful or you might just have an undefined index.  D'Oh!  As you might expect this causes a lot of head-scratching.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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