Pass all values of multi-checked checkboxes

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

Thu Mar 01, 2012 12:37 pm

I have a form in which the users can select more than one check box for each question, each question has four checkboxes with the same name but different values. These answers are then passed through an array which emails it to me. The problem I am having is rather than send all values for each question it only sends the last value. How do I get it to email all the values that are checked?
email part vastly cut down.

Code: Select all

$fields = array('date', 'name', 'sid', 'bdate', 'saddress', 'city', 'state', 'zip', 'cell', 'alternate', 'email', 'condition', 'classes', 'assignments', 'communication', 'evaluation', 'timeconstraints', 'attendance', 'campus', 'cocurricular', 'accommodationsused', 'tape', 'note', 'device', 'signl', 'caption', 'tcalculator', 'enlarger', 'braille', 'dragon', 'other', 'otherspecify', 'extend', 'environment', 'processor', 'spell', 'calculator', 'reader', 'waiver', 'reduced', 'oaccommodation', 'affirm', 'filled', 'parentname', 'fillother');
			
			//$to = "mhoover@dacc.edu";
			$to2 = "aabdelzaher@dacc.edu";
			//$to3 ="voliver@dacc.edu";
			$subject = "Request for Accommodations";
			$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 == "date") {
		$body.= "<strong>". " Today's date: "."</strong>&nbsp;&nbsp;" . $_POST[$efield] ."<p>";
	            } elseif($efield == "tape") {
		$body.= "<em>For Class Notes:</em><p><strong>". "Tape recorder:"." </strong>&nbsp;&nbsp;" . $_POST[$efield] .",<p>";
			} elseif($efield == "note") {
			$body.= "<strong>". "Note Taker: "."</strong>&nbsp;&nbsp;" . $_POST[$efield] .",<p><p>";
							
	}
	}
	}
Form fields

Code: Select all

<tr>	
<td style="width: 124px" class="style15">Tape Recorder<?php if(isset($problems['tape'])) {?>		<font color="red">*</font><?php } ?></td>
<td class="style9">	
		<input name="tape" id="tape1" type="checkbox" value="used before," <?php if(isset($_POST['tape'])) echo "checked"; ?>><span class="style15">
							</span>					
</td>
	<td class="style9">	
		<input name="tape" id="tape2" type="checkbox" class="style15" value="helpful in past," <?php if(isset($_POST['tape'])) echo "checked"; ?>> <span class="style15">
							</span>					
	<td class="style9">	
		<input name="tape" id="tape3"class="style15" type="checkbox" value="requesting from DACC" <?php if(isset($_POST['tape'])) echo "checked"; ?>><span class="style15">
							</span>					
	<td class="style9">	
		<input name="tape"  id="tape4" type="checkbox" value="NA" class="style15"<?php if(isset($_POST['tape'])) echo "checked"; ?>><span class="style15">
							</span>					
	</tr>
	<tr>	<td style="width: 124px" class="style15">Note Taker<?php if(isset($problems['note'])) {?>		<font color="red">*</font><?php } ?></td>
	<td class="style9">	
	<input name="note" type="checkbox" value="used before," <?php if(isset($_POST['note'])) echo "checked"; ?> class="style15"><span class="style15">
							</span>					
</td>
	<td class="style9">	
		<input name="note" type="checkbox" value= "been helpful in the past," <?php if(isset($_POST['note'])) echo "checked"; ?> class="style15"><span class="style15">
							</span>					
	<td class="style9">	
	<input name="note" type="checkbox" value= "requesting from DACC" <?php if(isset($_POST['note'])) echo "checked"; ?> class="style15"><span class="style15">
							</span>					
<td class="style9">	
<input name="note" type="checkbox" value="NA" <?php if(isset($_POST['note'])) echo "checked"; ?> class="style15"><span class="style15">
							</span>					
</tr>

User avatar
L33R
New php-forum User
New php-forum User
Posts: 143
Joined: Fri Dec 30, 2011 4:27 am
Location: Liverpool

Mon Mar 05, 2012 9:34 pm

try some thing like, simple two dimensional array. will keep all four values for each each question.

Code: Select all

<?php
	
	
if (isset($_POST['question'])) {
	foreach ($_POST['question'] as $q) {
		foreach ($q as $f) {
			print_R($f);
		}
	
	}


	}
 ?>
 <html>
 <head></head>
 <body>
 <form method="POST" action="">
<input type="text" name="question[0][0]" />
<input type="checkbox" name="question[0][1]" value="red" /> Red
<input type="checkbox" name="question[0][2]" value="blue" /> Blue
<input type="checkbox" name="question[0][3]" value="green" /> Green
<input type="checkbox" name="question[0][4]" value="yellow" /> Yellow


<input type="text" name="question[1][0]" />
<input type="checkbox" name="question[1][1]" value="red" /> Red
<input type="checkbox" name="question[1][2]" value="blue" /> Blue
<input type="checkbox" name="question[1][3]" value="green" /> Green
<input type="checkbox" name="question[1][4]" value="yellow" /> Yellow

<input type="text" name="question[2][0]" />
<input type="checkbox" name="question[2][1]" value="red" /> Red
<input type="checkbox" name="question[2][2]" value="blue" /> Blue
<input type="checkbox" name="question[2][3]" value="green" /> Green
<input type="checkbox" name="question[2][4]" value="yellow" /> Yellow



<input type="submit" name="submit" />
</form>
</body>

</html>



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

Tue Mar 06, 2012 7:27 am

L33R wrote:try some thing like, simple two dimensional array. will keep all four values for each each question.

Code: Select all

<?php
	
	
if (isset($_POST['question'])) {
	foreach ($_POST['question'] as $q) {
		foreach ($q as $f) {
			print_R($f);
		}
	
	}


	}
 ?>
 <html>
 <head></head>
 <body>
 <form method="POST" action="">
<input type="text" name="question[0][0]" />
<input type="checkbox" name="question[0][1]" value="red" /> Red
<input type="checkbox" name="question[0][2]" value="blue" /> Blue
<input type="checkbox" name="question[0][3]" value="green" /> Green
<input type="checkbox" name="question[0][4]" value="yellow" /> Yellow


<input type="text" name="question[1][0]" />
<input type="checkbox" name="question[1][1]" value="red" /> Red
<input type="checkbox" name="question[1][2]" value="blue" /> Blue
<input type="checkbox" name="question[1][3]" value="green" /> Green
<input type="checkbox" name="question[1][4]" value="yellow" /> Yellow

<input type="text" name="question[2][0]" />
<input type="checkbox" name="question[2][1]" value="red" /> Red
<input type="checkbox" name="question[2][2]" value="blue" /> Blue
<input type="checkbox" name="question[2][3]" value="green" /> Green
<input type="checkbox" name="question[2][4]" value="yellow" /> Yellow



<input type="submit" name="submit" />
</form>
</body>

</html>


Thanks for the reply L33R, I received a solution on another forum yesterday :)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests