/    Sign up×
Community /Pin to ProfileBookmark

Help with a list box

I need help passing multiple values from a list box to my processing page. I am not using a database since it is a short-term web page and it would take me longer to set one up with all the red tape I have to go through. I have also been searching to try to figure this out.

I have three list boxes that allow people to choose multiple times for a user to pick. When I click, submit it only pick-ups the last one that was clicked on.

Here is my code for my form:

<?php
if (!$HTTP_COOKIE_VARS[‘orgchaos’]){
?>
<html>
<head>
<title>Organized Chaos Volunteer Forum</title>
</head>
<body>
<form method=”post” action=”processchaos.php”>
<table border=0 width=”791″>
<tr>
<td colspan=”2″ align=”center”> <img src=”http://www.cofc.edu/connections/alumni/images/broadcastemail_images/chio_crest.jpg” alt=”Chi Omega”>
</td>
</tr>
<tr >
<td colspan=”2″ align=”center” style=”font-size:24px;”><strong>Organized Chaos Volunteer Registration Form</strong></td>
</tr>

<tr>
<td width=”333″ >Full name:</td>
<td width=”448″ ><input type=”textarea” name=”Fname” width=”250″></td>
</tr>

<tr>
<td>Primary Email:</td>
<td ><input type=”textarea” name=”peremail” width=”250″ ></td>
</tr>
<tr>
<td>Class Year:</td>
<td><select name=”classof” id=”classof”>
<option value=”96″ selected=”true”>1996</option>
<option value=”97″>1997</option>
<option value=”98″>1998</option>
<option value=”99″>1999</option>
<option value=”00″>2000</option>
<option value=”01″>2001</option>
<option value=”02″>2002</option>
<option value=”03″>2003</option>
<option value=”04″>2004</option>
<option value=”05″>2005</option>
<option value=”06″>2006</option>
</select>
</td>
</tr>
<td>T-shirt size:</td>
<td><select name=”Tshirt” id=”Tshirt”>
<option value=”s” selected=”true”>Small</option>
<option value=”m”>Medium</option>
<option value=”l”>Large</option>
<option value=”xl”>X-Large</option>

</select>
</td>
</tr>
<tr><td colspan=”2″>Please Check the dates you would like to help</td></tr>
<tr>
<td>Friday, August 18 at the Rivers & Kelly House</td>

<td><select name=”Tfri” id=”Tfri” size=”2″ multiple>
<option value=”f12to2″ selected=”true”>12to2 pm</option>
<option value=”f2to4″>2-4 pm</option>
<option value=”f4to6″>4-6pm</option>
<option value=”f6to9″>6-9 pm</option>
</select></td>
</tr>
<tr>
<td>Saturday, August 19 at Berry, College Lodge, McConnell, </td>
<td><select name=”Tsat” id=”Tsat” size=”2″ multiple>
<option value=”sa9to11″ selected=”true”>9-11 am</option>
<option value=”sa11to1″>11am-1 pm</option>
<option value=”sa1to3″>1-3pm</option>
<option value=”sa3to5″>3-5pm</option>
</option>
</select></td>
</tr>
<tr>
<td>Sunday, August 20 at McAlister
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Warren Place, Craig, Historic Houses</td>
<td><select name=”tsun” size=”2″ multiple id=”tsun”>
<option value=”su9to11″ selected=”true”>9-11 am</option>
<option value=”su11to1″>11am-1 pm</option>
<option value=”su1to3″>1-3pm</option>
<option value=”su3to5″>3-5pm</option>
</option>
</select></td></td>
</tr>
<tr>
<td colspan=”2″><p><font color=”#FF0000″><em>Please check the area you would like to help with:</em></font></p></td>
</tr>
<tr>
<td>Moving-In Students Belongings</td>
<td align=”center”><input type=”checkbox” value=”Movein”>
</tr>
<tr>
<td>Greeting Students and Parents</td>
<td align=”center”><input type=”checkbox” value=”Greeting”>
</tr>
<tr>
<td>Pedestrian Traffic Control</td>
<td align=”center”><input type=”checkbox” value=”Traffic”>
</tr>
<tr>

<tr>
<td>Comments:</td>
<td ><textarea name=”Comments” width=”350″ ></textarea></td>
</tr>
<tr>
<tr>
<td colspan=2 align=center><input type=submit value=”Submit Survey”></td>
</tr>
</table>
</form>

</body>
</html>”
<?php
end;}
else
{
?>
<html><body><p align=”center”>
<img src=”http://www.cofc.edu/connections/alumni/images/broadcastemail_images/chio_crest.jpg” alt=”Chi Omega”><br/><strong>Thank you, but you have already taken the survey.</strong></p></body></html>
<?php
end;}
?>

Here is my process web page:

<?PHP

setcookie (“orgchaos”, “Ture”, time() +7776000, “/”, “.cofc.edu”);
?>
<html>
<head>

</head>
<body>
<p align=”center”><img src=”http://www.cofc.edu/connections/alumni/images/broadcastemail_images/chio_crest.jpg” alt=”Chi Omega” ><br/><br/><br/><br/>
<?PHP
$Fname = $HTTP_POST_VARS[“Fname”];
$peremail = $HTTP_POST_VARS[“peremail”];
$classof = $HTTP_POST_VARS[“classof”];
$Tshirt = $HTTP_POST_VARS[“Tshirt”];
$Tfri = $HTTP_POST_VARS[“Tfri”];
$Tsat = $HTTP_POST_VARS[“Tsat”];
$tsun = $HTTP_POST_VARS[“tsun”];
$Comments = $HTTP_POST_VARS[“Comments”];
$Movein = $HTTP_POST_VARS[“Movein”];
$Greeting = $HTTP_POST_VARS[“Greeting”];
$Traffic = $HTTP_POST_VARS[“Traffic”];

$outputstring = $Fname.”,”.$peremail.”,”.$classof.”,”.$Tshirt.”,”.$Tfri.”,”.$Tsat.”,”.$tsun.”,”.Movein.”,”.Greeting.”,”.Traffic.”,”.$Comments.”n”;

// open file for appending
@ $fp = fopen(“orgchaos.txt”, “a”);
flock($fp, 2);
if (!$fp)
{
echo “<p align=”center”><strong> Your Survey could not be submitted at this time please try again later.”
.”</p></body></html>”;
exit;
}
fwrite($fp, $outputstring);

flock($fp, 3);
fclose($fp);
$names=explode(” “,$Fname);
echo $names[0].” thank you for your time in taking the the survey.”;
?>
</p>
</body>
</html>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJul 05.2006 — You are using outdated code,

put this in your process.php

[code=php]
<?php

echo("<pre>");
print_r(post);
echo("<pre>");
[/code]


Also seeings as this was your first post, please read the forum sticky

[url=http://www.webdeveloper.com/forum/showthread.php?t=102044]FAQ - Please Read Before Posting![/url], refer to the parts about surrounding your code in VB tags.
Copy linkTweet thisAlerts:
@NogDogJul 06.2006 — If you're using a select with multiple selections enabled, then give it a name ending with "[]", e.g.:
[code=html]
<select name="select_name[]">
[/code]

Then PHP will populate an array of values within the post array. In this example, they would be $_POST['select_name'][0], $_POST['select_name'][1], etc. You could then use foreach to loop through them:
[code=php]
foreach($_POST['select_name'] as $value)
{
// do something with $value
}
[/code]

Also, I'd recommend referencing the $_POST array instead of the $HTTP_POST_VARS array, as the latter is deprecated now (unless you're using a really old version of PHP).
×

Success!

Help @eugene_phil2000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...