Jump to content

Multiple Checkbox and mail ()


farnoise

Recommended Posts

Hi,

I'm a newbie in PHP and I have a form that has about 130 check boxes (I know its a lot) these 130 boxes has been splited in different groups and each group has 20 boxes, SO some values are same in different groups. so what I want to do is use the same name for all check boxes but different values, I tries checkbox[] function but all it gives me in my message line is "Array" for ex. if I check 10 different boxes it should give the value names for 10 different boxes but all i see is "Array".

 

PS: I dont want to echo my output, it has to be sent to recieptent via mail() function I got that all

 

here is my code:

 

check box name is = chkexpert[]  for all check boxes

 

HTML (only 3 of them is here)

_____

 

          <input name="chkexpert[]" type="checkbox" id="chkexpert" value="Voice mail"  />

            Voice mail <br />

            <input name="chkexpert[]" type="checkbox" id="chkexpert" value="Long Dst. Code"  />

            Long Dst. Code <br />

            <input name="chkexpert[]" type="checkbox" id="chkexpert" value="Laptop"  />

            Laptop <br />

.......

_______

 

PHP CODE

 

 

$chkexpert = addslashes($_POST['chkexpert']);

 

>>>

in my message line I have;

 

$message = " Hi, Your list is $chkexpert "

 

 

So when visitor choose 4 of that check boxes I'm recieving email says : Hi, Your list is Array

 

Thanks GUYS PLEASE HELP  :'( :'( :'(

Link to comment
https://forums.phpfreaks.com/topic/183617-multiple-checkbox-and-mail/
Share on other sites

By naming the checkboxes with [] at the end you are turning them into arrays. When you echo an array you simply get the word 'Array' as you have already found. You will need to convert it into a string that contains all the values in the array. There's lots of ways of doing it, but here's a quick example of one way.

 

function concat($a, $b) {
    if($a) {
       return $a . ", " . $b;
    } else {
        return $b;
    }
}
$input = array(1, 2, 3, 4, 5);
$output = array_reduce($input, "concat");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.