close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Getting data from checkbox group

Thread began 8/28/2009 9:21 am by Rune Brynestad | Last modified 5/30/2011 11:26 am by Brad Lawryk | 2433 views | 8 replies |

Rune Brynestad

Getting data from checkbox group

Hi All,

I'm using Universal Email in a PHP site and want to send the selected content of a checkbox group. When I do, only the value of one of the selected checkboxes are sent. I want to send all values in the selected checkboxes as a comma-separated string. I'm used to ASP (trying to learn PHP now) and it's handled automatically in that language.

I've heard about the implode() function, but I need help to implement it in my code.

My mail body goes like this:

//Start Mail Body
$MailBody = $MailBody . "<html><head></head><body>\r\n";
$MailBody = $MailBody . "<p>";
$MailBody = $MailBody . ((isset($_POST["Interests"]))?$_POST["Interests"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "</body></html>";
//End Mail Body

Live URL here: Checkboxes.php

Source code here: Test.zip

I'm not real familiar if at all with PHP, can someone shed some light on this for me and help to solve this issue?

Thanks.

Regards
Rune

Sign in to reply to this post

Jason ByrnesWebAssist

First the checkboxes need to include "[]" at the end to create an array. for example:

html:
<input type="checkbox" name="Interests[]" value="Guided walks" id="Interests_3" />





Then to use the implode function, change:

php:
$MailBody = $MailBody . ((isset($_POST["Interests"]))?$_POST["Interests"]:"");



to:

php:
$MailBody = $MailBody . ((isset($_POST["Interests"]))?implode(", ", $_POST["Interests"]):"");



the first argument in the implode function is the separator. I used ", " to create a comma separated list.

Sign in to reply to this post

Rune Brynestad

Superb

Thanks for helping me.

Regards
Rune

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Brad Lawryk

Originally Said By: Jason Byrnes
  First the checkboxes need to include "[]" at the end to create an array. for example:
html:
<input type="checkbox" name="Interests[]" value="Guided walks" id="Interests_3" />




Then to use the implode function, change:
php:
$MailBody = $MailBody . ((isset($_POST["Interests"]))?$_POST["Interests"]:"");


to:
php:
$MailBody = $MailBody . ((isset($_POST["Interests"]))?implode(", ", $_POST["Interests"]):"");


the first argument in the implode function is the separator. I used ", " to create a comma separated list.  



On what page is this code to change? I can't find it on my form or the template page. I am only getting the last box checked ... not all boxes checked.

Brad

Sign in to reply to this post

Jason ByrnesWebAssist

if you are using Universal Email 4 and have selected the option to create a file for the email and are using one of the built in templates, the post will be converted from the array automatically.

double check that the checboxes are named with the "[]" at the end:
name="myCheckboxes[]"

if you still having a problem send a copy of your page please.

Sign in to reply to this post

Brad Lawryk

Thanks,

I had put the [] in, but hadn't tested it yet because I was looking for the rest of that code. It works awesome. Thanks.

Does the Data Assist forms work the same way for checkboxes?

Sign in to reply to this post

Jason ByrnesWebAssist

No with DataAssist, you need to do it manually.

Here is an easy trick though:
When you bind the checkboxs in the insert or update wizard, it will include the brackets at the end of the name:

php:
<?php echo((isset($_POST["checkboxName[]"]))?$_POST["checkboxName[]"]:""?>


remove them:

php:
<?php echo((isset($_POST["checkboxName"]))?$_POST["checkboxName"]:""?>




then add the following code at line 1 of the page:

php:
<?php

if($_SERVER["REQUEST_METHOD"] == "POST")     {
    foreach(
$_POST as $key => $val) {
        if(
is_array($_POST[$key])) $_POST[$key] = implode(", "$_POST[$key]);
    }
}
?>
Sign in to reply to this post

Brad Lawryk

Originally Said By: Jason Byrnes
  Here is an easy trick though  



That worked perfect!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...