Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2012-04-04
6
276 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

808 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