You are here: Re: using lists in php and sending « PHP « IT news, forums, messages
Re: using lists in php and sending

Posted by Kae Verens on 03/08/05 20:49

Ross Hulford wrote:

> I have a list in php where the user can select 1 or more (rooms book in a
> b&b). The following code is part of the form.
>
> <select name="rooms" size="7" multiple>
> <option value="Single Standard">Single
> Standard</option>
> <option value="Single EnSuite">Single
> EnSuite</option>
> <option value="Double EnSuite">Double
> EnSuite</option>
> <option value="Twin En Suite">Twin En
> Suite</option>
> <option value="Family Standard">Family
> Standard</option>
> <option value="Family EnSuite">Family
> EnSuite</option>
> <option value="Tripple EnSuite">Tripple
> EnSuite</option>
> </select>
>
>
> And then I send using the mail() functin in PHP using the following code
> but the selected rooms do not display. I know it must be an array of sorts
> please help!!!
>
>
> msg .= "First Name: $firstname \n"; $msg .= "Second name: $surname \n";
> $msg .= "Email Address: $email \n"; $msg .= "Telephone: $telephone \n";
> $msg .= "Arrival Date: $arrival \n";
> $msg .= "Departure Date: $depart \n"; $msg .= "$adults Adults and
> $kids Children will be staying \n";
> $msg .= "We will require the following rooms $rooms\n";
> $msg .= "Message: $addinfo \n";
> $msg .= "---------------------------------------------------------\n\n";

you have no code written to build up $addinfo.

first, let's optimise that HTML a bit:

<select name="rooms[]" size="7" multiple="multiple">
<?
$arr=array('Single Standard','Single EnSuite','Double EnSuite',
'Twin En Suite','Family Standard','Family EnSuite',
'Triple EnSuite');
foreach($arr as $a)echo '<option>'.$a.'</option>';
?>
</select>

note the '[]' at the end of 'rooms[]'. that makes it an array.

now, assuming you are sending as POST, the next bit builds up $addinfo:

$arr=array();
foreach($_POST['rooms'] as $a=>$b)$arr[]=addslashes($a);
$addinfo=(count($arr))?
"Chosen Rooms:\n".join(',',$arr):
'No rooms chosen';

hope that's useful

--
kae verens
http://verens.com/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация