HELP - php code to post all list box values

Metse

Member
Joined
Jun 27, 2007
Messages
14
Reaction score
0
'am a beginner & am busy designing a site that has simple order-form which captures details of a cust and submit them throuth as an email using php, which works fine.

my problem is i added 2 list boxes, one(as a drop-down) pre-populated with items-to-order which allows the user to add items in-need to the second list box...

how do i sumbit all values of the 2nd list box along as an email. My code currently is:
.
.
$listbox2 = $_POST['listbox2'];
.
.
$message .= "items on order are: ";
$message .= $listbox2;
.
.

which doesn't work.

Please Help !!!!
 
Last edited:
Well first of all it is $_POST and not $POST and that variable is an array, so it should be $_POST['listbox2']
 
Hi malec.. I appreciate your response..

i mistakenly forgot to put in the underscore there:
my current code is as:

$listbox2 = $_POST('listbox2') and still doesn't work.


Thanks.
 
The second listbox sounds like you are allowing the user to select multiple items

if this is the case the name of the form element needs to be listbox2[] (this will tell php that the items being submitted are arrays)

Once submitted, you can then do the following

$listbox2 = $_POST['listbox2'];
$message .= "items on order are: ";
foreach ($listbox2 as $listbox_item) {
$message .= $listbox2_item . ' ';
}

hope this helps
 
And to save you some future problems I recommend you add untaint your inputs from the user to prevent nasty XSS in your email.

$listbox2 = $_POST['listbox2'];

should be

$listbox2 = addslashes(strip_tags($_POST['listbox2']));
 
Top
Sign up to the MyBroadband newsletter
X