Solved

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

Posted on 2012-04-04
6
275 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 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 83

Expert Comment

by:Dave Baldwin
ID: 37809248
0
 
LVL 109

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery GMAP3 Hierarchy 1 24
php simple error message 4 23
how can i make the array into an object? 4 30
Display images from mysql blob type (Not working) 9 26
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 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