473,511 Members | 10,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkbox array passes to script fine but doesn't mail right

Okay, I'm starting to get a little ticked off because I've worked for
hours on this and I can't seem to find the cause. I'm using PHP 5.1.6.
I'm trying to get the values of some form checkboxes along with another
fixed variable and pass them along in an email. For demonstration
purposes, I have checked the Wed and Fri checkboxes and set the time for
9:00 am.

<FORM ACTION="test.php" METHOD=POST>
<TABLE border="1" width="70%" >
<TR>
<td><input type="checkbox" name="NewClass[]" value="Mon" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Tue" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Wed" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Thu" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Fri" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Sat" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Sun" size="5"
maxlength="2"</td>
<TD><input type="text" name="NewClass-Time" size="5" maxlength="10"></TD>
</TR>
</TABLE>
<input type="submit" name="ClassList" value="Submit Survey Info"
class="button">
</form>

When I print out print_r($_POST);, I get everything passed correctly as:

Array
(
[NewClass] =Array
(
[0] =Wed
[1] =Fri
)

[NewClass-Time] =9:00 am
)

But when it gets emailed, the results listed on the email I get are as
follows:

NewClass: Array

NewClass-Time: 9:00 am

I stripped the processing script down to the barest of essentials. All
that's on it right now is:

foreach($_POST as $key =>
$value){if(!(!isset($value))){$set=1;}$message = $message . "$key:
$value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

$message = stripslashes($message);

$headers = "From: " . $_POST['name'] . " <" .$_POST['email'] . ">\n" .
"Return-Path: " . $_POST['email'] . "\n" . "Reply-To: " .
$_POST['email'] . "\n";

mail($my_email,$subject,$message,$headers);

Does anyone see what I'm obviously missing? How can I get the NewClass
array to pass each chosen value on in the email instead of printing out
"array"?
Jan 31 '07 #1
3 3610
Rik
JackM <no***@earthlink.netwrote:
Okay, I'm starting to get a little ticked off because I've worked for
hours on this and I can't seem to find the cause. I'm using PHP 5.1.6.
I'm trying to get the values of some form checkboxes along with another
fixed variable and pass them along in an email. For demonstration
purposes, I have checked the Wed and Fri checkboxes and set the time for
9:00 am.
When I print out print_r($_POST);, I get everything passed correctly as:

Array
(
[NewClass] =Array
(
[0] =Wed
[1] =Fri
)

[NewClass-Time] =9:00 am
)

But when it gets emailed, the results listed on the email I get are as
follows:

NewClass: Array

NewClass-Time: 9:00 am

I stripped the processing script down to the barest of essentials. All
that's on it right now is:

foreach($_POST as $key =
$value){if(!(!isset($value))){$set=1;}$message = $message . "$key:
$value\n\n";}
$value will always be set, even if it's an empty string (a lot of browsers
default to on though). So what the "if(!isset($value))" does?

foreach($_POST as $key =value){
$message = $key . ': '.((is_array($value)? implode(',',$value): $value);

}

--
Rik Wasmus
Jan 31 '07 #2
Rik wrote:
JackM <no***@earthlink.netwrote:
>When I print out print_r($_POST);, I get everything passed correctly as:

Array
(
[NewClass] =Array
(
[0] =Wed
[1] =Fri
)

[NewClass-Time] =9:00 am
)

But when it gets emailed, the results listed on the email I get are
as follows:

NewClass: Array

NewClass-Time: 9:00 am

I stripped the processing script down to the barest of essentials.
All that's on it right now is:

foreach($_POST as $key =>
$value){if(!(!isset($value))){$set=1;}$message = $message . "$key:
$value\n\n";}


$value will always be set, even if it's an empty string (a lot of
browsers default to on though). So what the "if(!isset($value))" does?

foreach($_POST as $key =value){
$message = $key . ': '.((is_array($value)? implode(',',$value):
$value);

}
So if I'm reading that correctly, that's another way of saying:

foreach($_POST as $key =$value){
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}

Close interpretation, maybe? At least the code works. ;-)
Feb 1 '07 #3
Rik
JackM <no***@earthlink.netwrote:
Rik wrote:
> foreach($_POST as $key =value){
$message = $key . ': '.((is_array($value)? implode(',',$value):
$value);
}

So if I'm reading that correctly, that's another way of saying:

foreach($_POST as $key =$value){
if(is_array($value)){
$message = $message . "$key: ".implode( ', ', $value)."\n\n";
} else {
$message = $message . "$key: $value\n\n";
}
}

Close interpretation, maybe? At least the code works. ;-)
Yup, except my code obviously didn't have the "\n\n" :-)
It's called the ternary operator, and saves a lot of lines/if-else blocks
for simple conditionals.

Also, '.=', will save some typing here:
$message .= "$key: ".implode( ', ', $value)."\n\n";
--
Rik Wasmus
Feb 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2112
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
2
8325
by: Ralph Freshour | last post by:
I have a function that I call to check or uncheck all checkboxes on a form - I use a 'master' checkbox to do this much like hotmail has to check all mail messages - the code works fine if I name my...
4
1669
by: Stefan Mueller | last post by:
To following code/script shows me the row number of the checkbox I've just clicked: <form name = "my_form" action = "" method = "post" accept-charset = "iso-8859-1"> <table name = "my_table"...
0
2783
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
2253
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
45
4763
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
29
3111
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
0
4078
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
3090
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.