Solved

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

Posted on 2012-04-04
6
271 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
Comment Utility
How about
<select name='car1'>
...
<select name='car2'>
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…
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.

771 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

11 Experts available now in Live!

Get 1:1 Help Now