OK I have an incident report form that has some check boxes on it. I tried using the implode function on the check boxes so that if more than one checkbox is checked all values will be passed to the array and emailed. I did this exactly the way I did it on a Request for accommodations form (that form works), but it does not pass all the values. I am sure I am missing something really simple but I can't find it. Any help would be appreciated.

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 = "example@example.com";
		$to2 = "example@example.com";
		//$to3 ="example@example.com";
		$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] . "&nbsp; <P>";
					} elseif($efield == "altercation1") {
						$body.= "<em>". " Altercation:&nbsp;"."</em>" . $altercation1 . "&nbsp;- &nbsp;";
					} elseif($efield == "altercation2") {
						$body.= "<strong>". " "."</strong>" . $altercation2 . " &nbsp; <p> ";
					} elseif($efield == "sexharass") {
						$body.= "<em>". " Sexual Harrasment: &nbsp;"."</em>" . $sexharass . "&nbsp; <p>";
					} elseif($efield == "property") {
						$body.=   "<em>". "Damage to Property:&nbsp; "."</em>" . $property . "&nbsp;<p> 	";
					} elseif($efield == "harm") {
						$body.=   "<em>". " Threat of Harm to Self or Others:&nbsp; "."</em>" . $harm 													."&nbsp;<p> ";
					} elseif($efield == "drugs") {
						$body.=   "<em>". " Drugs or Alcohol:&nbsp; "."</em>" . $drugs ."&nbsp;<p> ";
					} elseif($efield == "other") {
						$body.=   "<em>". " Other types of Occurrences: &nbsp;"."</em>" . $other 														."&nbsp;<p> ";

The Form

	<p class="style5">Type of Alleged Occurrence:<input name="occurrence" type="hidden" value="<?php { print 'Type of Occurrence'; }?>"></p>
								<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
	<table style="width: 100%">
		<tr>
			<td style="width: 21%; height: 57px;"><strong> Disruption:</strong><br>

				<input name="obscene" type="checkbox" value="Obscene Language" <?php if(isset($_POST['obscene'])) echo 		                               "checked"; ?>>
					<label >Obscene language </label>
		</td>
		<td style="width: 33%; height: 57px;">
						<strong> Sexual Harassment:</strong><br>

				<input name="sexharass[]" type="checkbox" value="Physical" <?php if(isset($_POST['sexharass']) && in_array('Physical',$_POST['sexharass'])) { echo 'checked'; } ?>>							
					<label>Physical </label>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

				<input name="sexharass[]" type="checkbox" value="Verbal" <?php if(isset($_POST['sexharass']) && in_array('Verbal',$_POST['sexharass'])) { echo 'checked'; } ?>>						
					<label>Verbal </label>
		</td>
	</tr>
	<tr>
		<td style="width: 21%; height: 57px;">
						<strong> Altercation:</strong><br>
				<input name="altercation1[]" type="checkbox" value="Verbal" <?php if(isset($_POST['altercation1']) && in_array('Verbal',$_POST['altercation1'])) { echo 'checked'; } ?>>
						<label>Verbal</label>
							<input name="altercation1[]" type="checkbox" value="Physical"<?php if(isset($_POST['altercation1']) && in_array('Physical',$_POST['altercation1'])) { echo 'checked'; } ?> >
						<label >Physical</label><br>

		<td style="width: 33%; height: 57px;"><strong>Involved in altercation:</strong><br>


							<input name="altercation2[]" type="checkbox" value="student/student" <?php if(isset($_POST['altercation2']) && in_array('student/student',$_POST['altercation2'])) { echo 'checked'; } ?>>

						<label>Student/Student </label>

							<input name="altercation2[]" type="checkbox" value="student/faculty-staff" <?php if(isset($_POST['altercation2']) && in_array('student/faculty-staff',$_POST['altercation2'])) { echo 'checked'; } ?>>
						<label >Student/Faculty-Staff </label>
		</td>
	</tr>
	<tr>
		<td>
						<strong> Theft/ Damage to Property:</strong><br>
							<input name="property[]" type="checkbox" value="DACC" <?php if(isset($_POST['property']) && in_array('DACC',$_POST['property'])) { echo 'checked'; } ?> >							<label >DACC </label>&nbsp;<span lang="en-us">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size="-1" 									face="Arial, Helvetica, sans-serif" align="left">

							<input name="property[]" type="checkbox" value="Self" <?php if(isset($_POST['property']) && in_array('Self',$_POST['property'])) { echo 'checked'; } ?> >							<label  >Self </label>



					</font>&nbsp;&nbsp;<br>
									</span>

							<input name="property[]" type="checkbox" value="Faculty/Staff" <?php if(isset($_POST['property']) && in_array('Faculty/Staff',$_POST['property'])) { echo 'checked'; } ?> >
						<label >Faculty/Staff </label>



		</td>
		<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>&nbsp;<span lang="en-us">&nbsp;&nbsp;&nbsp;
							<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>

							<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
							<span lang="en-us">
							<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>



			&nbsp;&nbsp;</span></font>
		</td>
	</tr>


	<tr>
		<td>
							<strong> Drugs/Alcohol:</strong><br>
							<input name="drugs[]" type="checkbox" value="Under the Influence" <?php if(isset($_POST['drugs']) && in_array('Under the Influence',$_POST['drugs'])) { echo 'checked'; } ?> >
						<label >Under the Influence </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<font size="-1" face="Arial, Helvetica, sans-serif" align="left">
							<input name="drugs[]" type="checkbox" value="Possession" <?php if(isset($_POST['drugs']) && in_array('Possession',$_POST['drugs'])) { echo 'checked'; } ?> >							<label  >Possession </label>



							</font>



		</td>
		<td>
							<strong> Other Occurrences:</strong><br>
							<input name="other[]" type="checkbox" value="Tresspassing" <?php if(isset($_POST['other']) && in_array('Tresspassing',$_POST['other'])) { echo 'checked'; } ?>  >							<label  >Trespassing </label>&nbsp;<span lang="en-us">&nbsp;&nbsp;&nbsp;<font size="-1" face="Arial, 							Helvetica, sans-serif" align="left">
							<input name="other[]" type="checkbox" value="Other" <?php if(isset($_POST['other']) && in_array('Other',$_POST['other'])) { echo 'checked'; } ?> >
						<label  >Other </label>



							</font><br>
									</span>
		</td>
	</tr>	
</table><p></p>

    Have you tried doing a [man]print_r/man on the entire $_POST array to see if it contains the data you expect?

    Can you elaborate on what "it does not pass all the values" means (e.g. what was the data you received vs. what you expected)?

      bradgrafelman;10998415 wrote:

      Have you tried doing a [man]print_r/man on the entire $_POST array to see if it contains the data you expect?

      Can you elaborate on what "it does not pass all the values" means (e.g. what was the data you received vs. what you expected)?

      no I haven't done a print_r(), partially because I am still unsure exactly how to use it.

      As for the passing all the values, if a user selects say two out of three check boxes in a group I want both values to be sent to the email, right now it is only sending the last one checked.

        bradgrafelman;10998415 wrote:

        Have you tried doing a [man]print_r/man on the entire $_POST array to see if it contains the data you expect?

        Can you elaborate on what "it does not pass all the values" means (e.g. what was the data you received vs. what you expected)?

        Never mind got it working, apparently all those times I thought the page was saving to the server it wasn't, ARRGHH I hate our hosting site! Stuff like this happens a lot!

          Write a Reply...