Current location: Hot Scripts Forums » Programming Languages » PHP » multiple select box with PHP


multiple select box with PHP

Reply
  #1 (permalink)  
Old 11-02-06, 03:20 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
multiple select box with PHP

I have a multiple select box.

PHP Code:

<select name="domain[]" multiple="multiple" size="4" class="selectbox">

      <
option value="1">Accounting</option>
      <
option value="2">Engineering</option>
      <
option value="3">Internet</option>
      <
option value="4">Sales</option>
</
select
The user need to select a domain name or more. In PHP I validate this select box as :

PHP Code:

$errormsg ""


if ($_POST['domain'] == "")
{
    
$errormsg .= "No domain name selected<br />";
    
$domain    "";
}
else 
{
    
$domain filterInput($_POST['domain']); // Stripslashes filtering enabled
}

if (
$errormsg == "")
{
   foreach(
$domain as $value)
   {
      print 
$value;   // I don't receive the value.
   
}
}
else
{
    print 
"error"

I want to get the selected values, for example if someone select "Accounting" and "Engineering" I want to see 1 and 2.

What I need to do ?

Thanks !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-02-06, 03:33 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
It should work, try to use filterInput() not on an array. Use it in the loop instead.
PHP Code:

foreach($domain as $value)

{
     print 
filterInput($value);   // I don't receive the value.

Edit, if you plan to receive only numeric values here, try using intval() instead.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-02-06, 03:55 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Nico ! work great !
Exist a way to check how many domains the user select ?

For example if user select more than 5 domains I want to show an error message.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-02-06, 04:01 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
This should do it.
PHP Code:

if (is_array($domain) AND sizeof($domain) > 5)

{
    exit(
'You can not select more than 5 domains.');
}

foreach(
$domain as $value)
{
    print 
$value;   // I don't receive the value.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-02-06, 04:26 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
thanks

thanks ! work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 09:26 AM
Working with multiple selections in a <select> box cstallins PHP 0 02-13-05 01:42 AM
Multiple column select box Dr-Leech HTML/XHTML/XML 1 08-31-04 12:27 AM
creating multiple directories using php seans9 PHP 3 01-28-04 02:00 AM


All times are GMT -5. The time now is 12:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.