Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP help with multiple select 1

Status
Not open for further replies.

postonoh

IS-IT--Management
Oct 19, 2010
3
US
<?php

/* Email Variables */

$emailSubject = Outreach Event';
$webMaster = 'test@webshelby.net';


/* Data Variables */

$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$address = $_POST['address'];
$city= $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$event = $_POST['Event'];
if ($event){
foreach ($event as $e){echo 'You selected ',$t,'<br />';}
}

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Company: $company <br>
Address: $address<br>
City: $city <br>
State: $state <br>
Postal Code: $zip <br>
Event: $event <br>

EOD;


$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://www.webshelby.net">
<style type="text/css">
<!--
body {
background-color: #244a30;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #fab323;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}

-->
</style>
</head>
<blockquote><center>
<img src="/images/logo.jpg" width="311" height="196" />
<div align="center">Registration Complete!<br>
You will return to home page in a few seconds !</div>
</center></blockquote>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>


I have a html page with this named rsvp.html:
php file name rsvp.php
<tr>
<td>Select Your Event:</td>
<td>
<select name="Event" size="5" multiple="multiple" id="Event">
<option value="1">S Certification (Day 1)</option>
<option value="2">S Certification (Day 2)</option>
<option value="3">Pre-Qual Meeting (Day 1)</option>
<option value="4">Pre-Qual Meeting (Day 2)</option>
</select> </td>
</tr>

when I select more then one it only gives me the one selected

What am I doing wrong?

I need for it to email me a selected events
 
You need to tell PHP to expect an array, otherwise it will get the selected options, but it will just overwrite the $_POST['event'] variable with the subsequent values.


Code:
<select name="Event[red][][/red]" size="5" multiple="multiple" id="Event">

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks, Receiving email but they say array instead of Selected text.
 
Well you aren't doing anything with your $event variable inside your $body you need to turn it into a string or something more useful.
Code:
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Company: $company <br>
Address: $address<br>
City: $city <br>
State: $state <br>
Postal Code: $zip <br>
[red]Event: $event <br>[/red]

EOD;

You expand $event before you stick it in your $body, but then totally forget about it, as you only output it to screen, but never do anything else with it.

Code:
$event = $_POST['Event'];
    if ($event){
     foreach ($event as $e){echo 'You selected ',$t,'<br />';}
    }

If you want to send it as a string in tour email, with breaks, you can simply implode it and be done with it.


Code:
$eventString=implode('<br',$event);
Then in your body just use $eventSring
Code:
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
Company: $company <br>
Address: $address<br>
City: $city <br>
State: $state <br>
Postal Code: $zip <br>
[red]Event: $eventString <br>[/red]

EOD;

I suggest reading up on arrays, and in the php online manual.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top