Solved

php form to email with checkboxes

Posted on 2007-04-10
6
252 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
The viewer will learn how to count occurrences of each item in an array.
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 …

948 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now