Solved

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

Posted on 2003-12-02
2
559 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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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 …

617 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