Form Checkbox Array Email Returns "Array" Instead of Input

I have a php form that I want to use a checkbox array on. the results should be emailed to me. Everything works except the result for the array comes out as “array” instead of the chosen answers.

It seems like the form I’m using is more complex than the other forms I’ve seen though… So I can’t seem to find the solution.

HTML:

<input type="checkbox" name="event[]" value="Summer Kick Off All-Nighter" />
          Summer Kick Off All-Nighter<br />
            <input type="checkbox" name="event[]" value="Beach Day" />
            Beach Day<br />
              <input type="checkbox" name="event[]" value="Middle School Only Guy Night" />
              Middle School Only Guy Night<br />
              <input type="checkbox" name="event[]" value="Beach Day" />
              Beach Day<br />
              <input type="checkbox" name="event[]" value="Middle School Only Pool Party/BBQ" />
              Middle School Only Pool Party/BBQ<br />
              <input type="checkbox" name="event[]" value="Bike Ride to Seal Beach" />
              Bike Ride to Seal Beach<br />
              <input type="checkbox" name="event[]" value="Summer Camp" />
              Summer Camp<br />
              <input type="checkbox" name="event[]" value="Hollywood Tour" />
              Hollywood Tour<br />
              <input type="checkbox" name="event[]" value="Raging Waters" />
              Raging Waters<br />
              <input type="checkbox" name="event[]" value="70's Skate" />
              70's Skate<br />
              <input type="checkbox" name="event[]" value="Psycho Beach Day" />
              Psycho Beach Day<br />
              <input type="checkbox" name="event[]" value="Pipeline  Small Group" />
              Pipeline  Small Group

PHP:

<?php


$flag        = 0;
$time_limit  = 1;         // time limit between 2 simultaneous mail from same IP in minutes
$subjectfile = 'subject_spam.txt';
$timefile    = 'time.txt';
$userfile    = 'user_spam.txt';
$from        =  $_POST[email];
$to          = "adam@asdf.com";



$subject     = "EVENT REGISTRATION";



$msg = "EVENT REGISTRATION

";
$msg .= "SENDER'S REGISTERED EVENTS:
$_POST[event]

";
$msg .= "SENDER'S NAME:
$_POST[name]

";
$msg .= "SENDER'S GRADE:
$_POST[grade]

";
$msg .= "SENDER'S SCHOOL:
$_POST[school]

";
$msg .= "SENDER'S BIRTHDAY:
$_POST[birthday]

";
$msg .= "SENDER'S PARENT OR GUARDIAN:
$_POST[parent]

";
$msg .= "SENDER'S EMERGENCY PHONE:
$_POST[emergency]

";
$msg .= "SENDER'S EMAIL:
$_POST[email]

";
$msg .= "SENDER'S ADDRESS 1:
$_POST[address]

";
$msg .= "SENDER'S ADDRESS 2:
$_POST[address2]

";
$msg .= "SENDER'S CITY:
$_POST[city]

";
$msg .= "SENDER'S ZIP:
$_POST[zip]

";
$msg .= "SENDER'S HOME PHONE NUMBER:
$_POST[phone]

";
$msg .= "STUDENT'S CELL PHONE:
$_POST[cell]

";
$msg .= "MYSPACE VIRB FACEBOOK URL:
$_POST[myspace]

";


if(!checkRefferer()){
     $flag=1;
}


if(!is_valid_email($from)){
     $flag=1;
}

if(!checkIp()){
     $flag = 1;
}

if(!checkSubject($subject)){
     $flag =1;
}


if(!userSpam($from)){
     $flag = 1;
}


if($flag==0){
     $send_from = "From: $from
";
     mail($to, $subject, $msg, $send_from);

     $lip =  $_SERVER['REMOTE_ADDR'];
     $admin_address = "From: admin@asdf.com
";
     $next_msg = "IP address of the earlier email was ".$lip;
     mail($to, "IP address of the earlier email",$next_msg,$admin_address);
     saveIp();
}else{
//do whatever if spam is found

print "Please check your submission for errors or wait at least one minute between submissions.";

exit;

//


}







function is_valid_email($from)
{
     if(preg_match("/@/",$from)){
          if(preg_match("/\
|\;|\,|bcc|cc|\@.*\@/i",$from)){
               return 0;
          }else{
               return 1;
          }
     }else{
          return 0;
     }
          
}




function getString($file)
{
     $fp = fopen($file,r);
     $content = fread($fp,filesize($file));
     fclose($fp);
     return $content;
}


function writeString($file,$str)
{
     $fp = fopen($file,w);
     fwrite($fp,$str,strlen($str));
     fclose($fp);     
}

function appendString($file,$str)
{
     $fp = fopen($file,a);
     fwrite($fp,$str,strlen($str));
     fclose($fp);          
}


function saveIp()
{
     global $timefile;
     $ip = $_SERVER['REMOTE_ADDR'];
     $str = $ip.'-'.time().',';
     if(!file_exists ($timefile)){
          writeString($timefile,$str);
     }else{
          appendString($timefile,$str);
     }
}




function checkIp()
{
     global $time_limit,$timefile;     
     $now = time();

     if(!file_exists ($timefile)){
          writeString($timefile," ");
     }
          
     $ip = $_SERVER['REMOTE_ADDR'];
     $content = getString($timefile);
     preg_match_all("/($ip)-([0-9]*)/",$content,$match);
     $last_logged =  $match[2][count($match[2])-1];
     if(($now - $last_logged)<=(60*$time_limit))
         return 0;
     else
         return 1;

}




function checkSubject($subject)
{
     global $subjectfile;
     $str = getString($subjectfile);
     preg_match_all("/.*/",$str,$match);

     $j=0;
     for($i=0;$i<count($match[0]);$i++)
     {
          if($match[0][$i]!=''){
             $arr[$j] = rtrim($match[0][$i]);
             $j++;
          }
     }

     $arr = array_unique($arr);
     for($i=0;$i<count($arr);$i++){
          $temp = trim($arr[$i]);
          if(preg_match("/$temp/i",$subject)){
               return 0;
          }
     }
     return 1;
}



function userSpam($from)
{
     global $userfile;
     $str = getString($userfile);
      if (preg_match ("/$from/i",$str))
           return 0;
      else
           return 1;           
}

     


function checkRefferer()
{
     $reff  = $_SERVER['HTTP_REFERER'];
     $host  = $_SERVER['HTTP_HOST'];
     if(preg_match("/$host/",$reff)){
          return 1;
     }else{
          return 0;
     }
}

?>

Email Returns w/:

SENDER’S EVENTS:
Array

SENDER’S NAME:
name

SENDER’S GRADE:
grade

I’m betting it’s something really simple… But I’ve been playing with it all day and can’t seem to get it to work.

Thanks in advance!

Or you can give each individual checkbox a unique name.


<?php
	$events = $_POST['event'];
	foreach ( $events as $event )
	{
		echo "$event<br/>";
	}
?>

[QUOTE=djheru;2341372]Or you can give each individual checkbox a unique name.[/QUOTE]

This is what I ended up doing, thanks!

My new code looks like:

<input type="checkbox" name="event1" value="Summer" />
          Summer Kick Off All-Nighter<br />
            <input type="checkbox" name="event2" value="Beach Day" />
            Beach Day<br />
              <input type="checkbox" name="event3" value="Middle" />
              Middle School Only Guy Night<br />
              <input type="checkbox" name="event4" value="Beach" />
              Beach Day<br />
              <input type="checkbox" name="event5" value="Middle" />
              Middle School Only Pool Party/BBQ<br />
              <input type="checkbox" name="event6" value="Bike" />
              Bike Ride to Seal Beach<br />
              <input type="checkbox" name="event7" value="Summer" />
              Summer Camp<br />
              <input type="checkbox" name="event8" value="Hollywood" />
              Hollywood Tour<br />
              <input type="checkbox" name="event9" value="Raging" />
              Raging Waters<br />
              <input type="checkbox" name="event10" value="Skate" />
              70's Skate<br />
              <input type="checkbox" name="event11" value="Psycho" />
              Psycho Beach Day<br />
              <input type="checkbox" name="event12" value="Pipeline" />
              Pipeline  Small Group
$msg .= "REGISTER FOR EVENTS:
$_POST[event1]
$_POST[event1]
$_POST[event2]
$_POST[event3]
$_POST[event4]
$_POST[event5]
$_POST[event6]
$_POST[event7]
$_POST[event8]
$_POST[event9]
$_POST[event10]
$_POST[event11]
$_POST[event12]

";

Not the perfect solution, but it works! Thanks!

[QUOTE=simplistik;2341390]


<?php
	$events = $_POST['event'];
	foreach ( $events as $event )
	{
		echo "$event<br/>";
	}
?>

[/QUOTE]

This works perfect for the confirmation page, but didnt send the results to email… which is what the main problem was. Thanks though!

[QUOTE=sosADAMsos;2341477]
This works perfect for the confirmation page, but didnt send the results to email… which is what the main problem was. Thanks though![/QUOTE]
ummm … that’s cause you used it wholesale … instead of modifying it to work in your code. i gave you psuedo code for your solution, if you wanted it to work for your script all you have to do is replace echo with

$msg .= "$event
"

giving those checkboxes individual names like that is sloppy imo

giving those checkboxes individual names like that is sloppy imo

Unless you want to create a javascript function to check for required checkboxes and display an error message. Dealing with MEANINGFUL checkbox element names is easier than referring to a numerically indexed array.

[QUOTE=djheru;2341856]Unless you want to create a javascript function to check for required checkboxes and display an error message. Dealing with MEANINGFUL checkbox element names is easier than referring to a numerically indexed array.[/QUOTE]
if ALL you’re going to do is list them out then it’s not needed. what you mentioned isn’t even the same scenario as this, but even in your scenario you would still do the required check server-side, not w/ JS

Why would you want to parse an unnecessary array on the server just to see if required check boxes are checked when you could just use javascript to detect them? If the checkboxes have meaningful names, you can easily ceate the error message to display.

I’m not of the school that believes that there is only one right way to do things. I would say that if all you are doing is listing out the values of the checkboxes, put them in an array. If you are using them for any kind of logic, give them unique meaningful names.

But as I said, I’m not going to insist that there is only one way to do things. Whatever method is faster for you to code, easier to debug, easier to maintain and runs faster on the server is the method you should use.

if you disable JS the check wouldn’t work, that’s all i was saying