Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-12-02
2
Medium Priority
?
560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 320 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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.

670 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