Solved

php form to email with checkboxes

Posted on 2007-04-10
6
278 Views
Last Modified: 2010-07-27
In a PHP form to Email I have 5 Checkboxes such as:

<input type="checkbox" name="Subject_Requested[]" id="English" value="English" />English
<input type="checkbox" name="Subject_Requested[]" id="Science" value="Science" />Science
<input type="checkbox" name="Subject_Requested[]" id="Maths"  value="Maths" /> Maths

I need to print/echo only the one that has been checked by the user:
Since the output is sent by email i included all the variables inside of the email "body" such as:

===========================================
$body ="

foreach ($Subject_Requested as $value) {
echo $value.'<br />'
};"

=============================================

But it does not seem to work. I know I should create the loop outside the "body" and then call the function, but I do not know how and I am not sure if I am right :-)

Please help..........
0
Comment
Question by:Refael
  • 3
6 Comments
 
LVL 10

Expert Comment

by:sakuya_su
ID: 18887704
I had the following test files:

<form action="test.php" method="post">
<input type="checkbox" name="Subject_Requested[]" id="English" value="English" />English
<input type="checkbox" name="Subject_Requested[]" id="Science" value="Science" />Science
<input type="checkbox" name="Subject_Requested[]" id="Maths"  value="Maths" /> Maths
<INPUT type="submit" value="Send">
</form>
----------------
<?php

foreach ($Subject_Requested as $value) {
echo $value.'<br />';
}

?>

and it worked fine?
0
 

Author Comment

by:Refael
ID: 18887719
sakuya_su

the problem is that i have this code inside of the email body....
$body ="foreach ($Subject_Requested as $value) {echo $value.'<br />'};"
it does bot read it ?! you know what i mean?

0
 

Author Comment

by:Refael
ID: 18887727
this is what i get in the email:

foreach (Spanish as ) { echo .'
'; }

i think its because its within the duble quote of the body message.....
0
 

Author Comment

by:Refael
ID: 18887812
i have found the solution.....

outside the body i added:
=======================================
foreach($_POST['Subject_Requested']as $value){
$check_msg.="$value<br>";}
======================================

then in the body i just the $check_msg

work great!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 19509357
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question