Pass value of hidden field to an Array for email body

the mail() function

Moderators: egami, macek, gesf

Post Reply
Inky1231
New php-forum User
New php-forum User
Posts: 23
Joined: Thu Jan 19, 2012 8:01 am

Mon Jan 30, 2012 11:11 am

Ok here is what I am trying to do. I have a PHP email form (Modified from previous build not by me) that sends the values from form fields to an array. I am trying to add a hidden field to add a piece of text into the email body via the array so it gets put in the right place but I can't get the value of the hidden field to pass into the array or email, I have tried various ways of doing this. can you help me.

Here is the (current) code of the hidden field

Code: Select all

<p class="style5">Type of Alleged Occurrence:<input name="occurrence" type="hidden" value="<?php  print 'Type of Occurrence' ?>"></p>
Here is the PHP for the array and email body

Code: Select all

	<?php
		$problems = array();
		$showform = 0;
		 $errorMessage = "";
		
		function validate($field, $value) {
		
			// || $field == "id" || $field == "phone" || $field == "course" || $field == "instructor"
		
			/*if ($field == "name" || $field == "email" || $field == "computers" || $field == "info") {*/
				if ($value == "") {
					return 0;
				} else {
					return 1;
				}
			/*}*/
			
			/*if ($field == "system" || $field == "browser" || $field == "issue" || $field == "multiple") {
				if ($value == "----" || $value == "") {
					return 0;
				} else {
					return 1;
				}
			}*/
		
		}
	
		if($_POST) {
		
			//'id','phone','course','instructor',
		
			$fields = array('name','title', 'month','day','year', 'time', 'building', 'room', 'location', 'person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness', 'acttaken', 'followact');
			$x = 0 - 1;
			
			foreach($fields as $field) {
			
				if(isset($_POST[$field])) {
					$validation = validate($field, $_POST[$field]);
					if ($validation == 1) {
						$x++;	
						$info[$x] = $_POST[$field];
					} else {
						$problems[$field] = 1;
						$showform = 1;
					}
				} else {
					$problems[$field] = 1;
					$showform = 1;
				}
			}
		
		} else {
			$showform = 1;
		}
		
		if(count($problems) < 1 && $_POST) {
		
			// DO THE MAILING HERE

			$fields = array('title', 'name','month','day','year', 'time', 'building', 'room', 'location', 'title1','person',  'phone1', 'title2', 'person2', 'phone2','title3','person3',  'phone3','title4','person4',  'phone4','occurrence','obscene','altercation1', 'altercation2', 'sexharass', 'property', 'harm',  'explanation', 'security', 'police', 'witness','wtitle1', 'wperson',  'wphone1', 'wtitle2', 'wperson2', 'wphone2','wtitle3','wperson3',  'wphone3', 'acttaken', 'followact');
			
			//$to = "mhoover@dacc.edu";
			$to2 = "aabdelzaher@dacc.edu";
			$to3 ="ampeck@earthlink.net";
			$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>";
			

			$body =   $greet  ; 
		

			$cn = 1;
	
			
			foreach($fields as $efield) {
			
				
				if(isset($_POST[$efield])) {
				
					if($efield == "type3" || $efield == "type4" || $efield == "type5" || $efield == "type6" || 							$efield == "type7" || $efield == "type8" || $efield == "type9" ) {
						$body.= "<strong>". "Type of Occurrence:".  "</strong> &nbsp;&nbsp;" . $_POST[$efield] . 						"<p>";
							$cn++;
						} elseif($efield == "occurrence") {
							$body.=   " 		test						&nbsp; <P>";

						} elseif($efield == "obscene") {
							$body.= "<strong>". " Type of Occurrence: "."</strong><p>" . $_POST[$efield] . " 								&nbsp; <P>";
						} elseif($efield == "altercation1") {
							$body.= "<strong>". " Type of Occurrence: "."</strong><p>" ."<em>". " Altercation: 								"."</em>" . $_POST[$efield] . "&nbsp;- &nbsp; 							";
						} elseif($efield == "altercation2") {
							$body.= "<strong>". " "."</strong>" . $_POST[$efield] . " &nbsp; <p> ";
						} elseif($efield == "sexharass") {
							$body.= "<strong>". " Type of Occurrence: "."</strong><p>" ."<em>". " Sexual 									Harrasment: "."</em>" . $_POST[$efield] . "&nbsp; 								<p>";
						} elseif($efield == "property") {
							$body.= "<strong>". " Type of Occurrence: "."</strong><p>" ."<em>". "Damage to 								Property: "."</em>" . $_POST[$efield] . "&nbsp;<p> 	";
						} elseif($efield == "harm") {
							$body.= "<strong>". " Type of Occurrence: "."</strong><p>" ."<em>". " Threat of Harm 							to Self or Others: "."</em>" . 	$_POST[$efield] ."&nbsp;<p> ";

						} elseif($efield == "title") {
							$body.= "<strong>"."Name of Person Filing Report: " ."</strong>" . $_POST[$efield] . 							" ";

						} elseif($efield == "name") {
							$body.= "   " . $_POST[$efield] . "<p><hr color=' #33cc66'>";
					
						} elseif($efield == "month") {
							$body.= "<strong>". "Date of Occurrence : "."</strong>" . $_POST[$efield] . " &nbsp; 							";
						} elseif($efield == "day") {
							$body.= "<strong>". " "."</strong>" . $_POST[$efield] . ", &nbsp;  ";

						} elseif($efield == "year") {
							$body.= "<strong>". " "."</strong>" . $_POST[$efield] . " &nbsp;  ";

						} elseif ($efield == "time") {
							$body.= "<strong>"."Time: " ."</strong>". $_POST[$efield] . "</p>";
						} elseif ($efield == "building") {
							$body.= "<strong>"."Building: ". "</strong>" . $_POST[$efield] . " &nbsp; &nbsp;&nbsp;							&nbsp;&nbsp;  ";
						} elseif ($efield == "room") {
							$body.= "<strong>"."Room: "."</strong>" . $_POST[$efield] . "<p>";
						} elseif ($efield == "location") {
							$body.= "<strong>"."Description of Location: ". "</strong>" . $_POST[$efield] . "<p>							<hr color=' #33cc66'>";
						} elseif ($efield == "title1") {
							$body.= "<strong>"."First Person involved: ". "</strong>" . $_POST[$efield] . "&nbsp;							&nbsp; ";
						} elseif ($efield == "person") {
							$body.= "&nbsp;&nbsp;&nbsp;" . $_POST[$efield] . "<p>";
									
						} elseif ($efield == "phone1") {
							$body.= "<strong>". "Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #								33cc66'>";
						} elseif($efield == "title2" && $_POST[$efield] != '') {
							$body.= "<strong>"."Second Person involved: ". "</strong>" . $_POST[$efield] . "&nbsp;							&nbsp; ";
						} elseif($efield == "person2" && $_POST[$efield] != '') {
							$body.= "  " . $_POST[$efield] . "<p> ";
						} elseif($efield == "phone2" && $_POST[$efield] != '') {
							$body.= "<strong>". "Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #								33cc66'>";
						} elseif($efield == "title3" && $_POST[$efield] != '') {
							$body.="<strong>". "Third Person involved: ". "</strong>" . $_POST[$efield] . " &nbsp;							&nbsp; ";
						} elseif($efield == "person3" && $_POST[$efield] != '') {
							$body.= " &nbsp;&nbsp; " . $_POST[$efield] . "<p>";
				
						} elseif($efield == "phone3" && $_POST[$efield] != '') {
							$body.= "<strong>"."Phone: "."</strong>" . $_POST[$efield] . "<p><hr color=' #									33cc66'>";
						} elseif($efield == "title4" && $_POST[$efield] != '') {
							$body.="<strong>". "Fourth Person Involved: ". "</strong>" . $_POST[$efield] . " 								&nbsp;&nbsp; ";
						} elseif($efield == "person4" && $_POST[$efield] != '') {
							$body.= "&nbsp;&nbsp; " . $_POST[$efield] . "<p>";
						} elseif($efield == "phone4" && $_POST[$efield] != '') {
							$body.= "<strong>"."Phone: ". "</strong>" . $_POST[$efield] . "<p><hr color=' #									33cc66'>";
						} elseif ($efield == "explanation") {
							$body.= "<strong>"."Detailed Explanation: ". "</strong>" . $_POST[$efield] . "<p><hr 							color=' #33cc66'>";
						} elseif ($efield == "security") {
							$body.= "<strong>"."Security called: ". "</strong>" . $_POST[$efield] . "<p>";
						} elseif ($efield == "police") {
							$body.= "<strong>"."Police called: "."</strong>" . $_POST[$efield] . "<p>";
						} elseif ($efield == "witness") {
							$body.= "<strong>"."Were there witnesses: "."</strong>" . $_POST[$efield] . "<p><hr 							color=' #33cc66'>";
						} elseif($efield == "wtitle1" && $_POST[$efield] != '') {
							$body.= "<strong>"."Witness: "."</strong>" . $_POST[$efield] . "&nbsp;&nbsp; ";
						} elseif($efield == "wperson" && $_POST[$efield] != '') {
							$body.= "&nbsp;&nbsp;" . $_POST[$efield] . "<p>";
						} elseif($efield == "wphone1" && $_POST[$efield] != '') {
							$body.= "<strong>"."Phone : "."</strong>" . $_POST[$efield] . "<p><hr color=' #									33cc66'>";
						 }elseif($efield == "wtitle2" && $_POST[$efield] != '') {
							$body.= "<strong>"."Second witness: ". "</strong>" . $_POST[$efield] . "&nbsp;&nbsp; 							";
						} elseif($efield == "wperson2" && $_POST[$efield] != '') {
							$body.= " &nbsp;&nbsp; " . $_POST[$efield] . "<p>";
						} elseif($efield == "wphone2" && $_POST[$efield] != '') {
							$body.= "<strong>"."Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #								33cc66'>";
				
						} elseif($efield == "wtitle3" && $_POST[$efield] != '') {
							$body.="<strong>". "Third witness: ". "</strong>" . $_POST[$efield] . " &nbsp;&nbsp; 							";
						} elseif($efield == "wperson3" && $_POST[$efield] != '') {
							$body.= "&nbsp;&nbsp;  " . $_POST[$efield] . "<p>";
				
						} elseif($efield == "wphone3" && $_POST[$efield] != '') {
							$body.= "<strong>". "Phone: "."</strong>" . $_POST[$efield] . "<p><hr color=' #									33cc66'>";
						} elseif ($efield == "acttaken") {
							$body.= "<strong>"."Immediate Action Taken: " ."</strong>". $_POST[$efield] . "<p><hr 							color=' #33cc66'>";
						} elseif ($efield == "followact") {
							$body.= "<strong>". "What Follow-up Action will be taken: " ."</strong>". 										$_POST[$efield] . "<p><hr color=' #33cc66'>";
}
				}
			}
			
			//mail($to, $subject, $body, $headers);
			mail($to2, $subject, $body, $headers);
			mail($to3, $subject, $body, $headers);
			?>
			<p class="style1">Your report has been submitted.<br><br></p>
			<?php
		
		}
		
		if($showform == 1) {
	?>

TheProdigyGuy
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Mon Jan 30, 2012 12:32 pm

Hello Inky1231)
I think it will work:
on line no: 32 and 60: *replace $fields: with

just copy paste:

Code: Select all

$fields = array('occurence','name','title', 'month','day','year', 'time', 'building', 'room', 'location', 'person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness', 'acttaken', 'followact');     
Will work.

Inky1231
New php-forum User
New php-forum User
Posts: 23
Joined: Thu Jan 19, 2012 8:01 am

Tue Jan 31, 2012 7:20 am

TheProdigyGuy wrote:Hello Inky1231)
I think it will work:
on line no: 32 and 60: *replace $fields: with

just copy paste:

Code: Select all

$fields = array('occurence','name','title', 'month','day','year', 'time', 'building', 'room', 'location', 'person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness', 'acttaken', 'followact');     
Will work.
Thank you! I never thought to put it in the first $fields array as that array sets the required fields!! you are awesome! I spent forever trying to figure that out yesterday!

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest