Solved

PHP - Checkboxes, mail() and foreach() - getting only last checkbox value...

Posted on 2003-12-02
2
555 Views
Last Modified: 2006-11-17
Here is the HTML

I have a large form to process and send through email, part of which has a set of 6 checkboxes named "experience" with six different values...

Here is the PHP code in question...

      foreach($_POST['expertise'] as $value)
            {
                  $expert .= "$value   ";
            }
      extract($_POST);
      if( mail($mail_to,$mail_subject,
            "\tTitle: ".$title.
            "\n\tName: ".$name.
            "\n\tEmail: ".$email.
            "\n\n\tCompany: ".$company.
            "\n\n\tAddress: ".$address.
            "\n\tCity: ".$city.
            "\n\tState / Province: ".$province.
            "\n\tPostal Code: ".$postal.
            "\n\n\t Phone Number: ".$phone."   Extension: ".$extension.
            "\n\tCell: ".$cell.
            "\n\tFax: ".$fax.
            "\n\nExperience: \n====================\n".$experience.
            "\n\nArea(s) of Expertise: \n====================\n".$expert.
            "\n\nCapabilities: \n====================\n".$capabilities.
            "\n\nProfessional Designations: \n====================\n".$designations.
            "\n\nIndustry Sector(s): \n====================\n".$sectors.
            "\n\nComments / Questions: \n====================\n".$comments,
            "From: ".$email."\r\n".
            "Reply-To: ".$email."\r\n") )

I thought the foreach() code would do the trick, but I only get the last checkbox value selected to appear in the email. I used the "." operator so it would add on the values to the variable, so I don't know what i'm doing wrong here. The rest of the form works fine.

Thanks in advance for your help.


Dean
http://www.dcwebsitedesign.com
0
Comment
Question by:chandldj
2 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 80 total points
ID: 9860398
Are you sure you aren't refering to a field named expertise (going  by your PHP Code)

if so change something like

<input type="checkbox" name="expertise" value="whatever">

to something like

<input type="checkbox" name="expertise[]" value="whatever">

Note that I'm changing experience to expertise[] by adding square brackets.

Then you can

$expert = implode(" and ", $expertise); // or something like that.
0
 

Author Comment

by:chandldj
ID: 9860727
You are absolutely right... i'm a bonehead - duh... I was trying to do this for the experience variable...

The implode function worked great...

Thanks!


Dean
http://www.dcwebsitedesign.com

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

Suggested Solutions

Title # Comments Views Activity
mimic google as my ip 11 53
object oriented programming comparison 5 54
WordPress syntax 2 26
Put radio button in my form but already has components from my database 4 45
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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 …

910 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