Solved

php form to email with checkboxes

Posted on 2007-04-10
6
243 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

744 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

12 Experts available now in Live!

Get 1:1 Help Now