Ok I have a form with multiple check boxes, these are not all required. When the form is submitted the checkboxes which have an implode set for them and were not checked come back with the PHP warning and the Notice that implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed .
How can I get rid of this when the checkbox is left empty?
Here is an example of my form areas
<td>
<strong> Threat of Harm to Self or Others:</strong><br>
<input name="harm[]" type="checkbox" value="Student/Student" <?php if(isset($_POST['harm']) && in_array('Student/Student',$_POST['harm'])) { echo 'checked'; } ?> >
<label >Student/Student </label> <span lang="en-us">
<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
<input name="harm[]" type="checkbox" value="Self" <?php if(isset($_POST['harm']) && in_array('Self',$_POST['harm'])) { echo 'checked'; } ?>>
<label >Self </label>
<br>
<input name="harm[]" type="checkbox" value="Student/Faculty-Staff" <?php if(isset($_POST['harm']) && in_array('Student/Faculty-Staff',$_POST['harm'])) { echo 'checked'; } ?>>
<label>Student/Faculty-Staff </label>
</font></span></td>
</tr>
Here is the PHP
$fields = array('title', 'name','date', 'time', 'building', 'room', 'location', 'title1','person', 'phone1', 'title2', 'person2', 'phone2','title3','person3', 'phone3','title4','person4', 'phone4','occurrence','obscene','altercation1', 'altercation2', 'sexharass', 'property', 'harm', 'drugs', 'other', 'explanation', 'security', 'police', 'witness','wtitle1', 'wperson', 'wphone1', 'wtitle2', 'wperson2', 'wphone2','wtitle3','wperson3', 'wphone3', 'acttaken', 'followact');
//$to = "mhoover@dacc.edu";
$to2 = "aabdelzaher@dacc.edu";
// $to3 ="voliver@dacc.edu";
$subject = "Incident / Unusual Occurrence Report";
$headers ='MIME-Version: 1.0' .PHP_EOL;
$headers .='Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= "From: noreply@dacc.edu\r\n" . "X-Mailer: php";
$greet = "The following was submitted on " . date("F j, Y, g:i a") . "<p><p>";
$sexharass = implode(', ', $_POST['sexharass']);
$altercation1 = implode(', ', $_POST['altercation1']);
$altercation2 = implode(', ', $_POST['altercation2']);
$harm = implode(', ', $_POST['harm']);
$property = implode(', ', $_POST['property']);
$drugs = implode(', ', $_POST['drugs']);
$other = implode(', ', $_POST['other']);
$body = $greet ;
$cn = 1;
foreach($fields as $efield) {
if(isset($_POST[$efield])) {
if($efield == "occurrence") {
$body.= "<strong>". " Type of Occurrence: "."</strong><p>";
} elseif($efield == "obscene" ) {
$body.= $_POST[$efield] . " <P>";
} elseif($efield == "altercation1" && $_POST[$efield] != '') {
$body.= "<em>". " Altercation: "."</em>" . $altercation1 . " - ";
} elseif($efield == "altercation2" && $_POST[$efield] != '') {
$body.= "<strong>". " "."</strong>" . $altercation2 . " <p> ";
} elseif($efield == "sexharass" && $_POST[$efield] != '') {
$body.= "<em>". " Sexual Harrasment: "."</em>" . $sexharass . " <p>";
} elseif($efield == "property" && $_POST[$efield] != '') {
$body.= "<em>". "Damage to Property: "."</em>" . $property . " <p> ";
} elseif($efield == "harm" && $_POST[$efield] != '') {
$body.= "<em>". " Threat of Harm to Self or Others: "."</em>" . $harm ." <p> ";
} elseif($efield == "drugs" && $_POST[$efield] != '') {
$body.= "<em>". " Drugs or Alcohol: "."</em>" . $drugs ." <p> ";
} elseif($efield == "other" && $_POST[$efield] != '') {
$body.= "<em>". " Other types of Occurrences: "."</em>" . $other ." <p> ";