Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

762 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

19 Experts available now in Live!

Get 1:1 Help Now