473,586 Members | 2,633 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.ph p" 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(!(!i sset($value))){ $set=1;}$messag e = $message . "$key:
$value\n\n";} if($set!==1){he ader("location: $_SERVER[HTTP_REFERER]");exit;}

$message = stripslashes($m essage);

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

mail($my_email, $subject,$messa ge,$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 3622
Rik
JackM <no***@earthlin k.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(!(!i sset($value))){ $set=1;}$messag e = $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($val ue))" does?

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

}

--
Rik Wasmus
Jan 31 '07 #2
Rik wrote:
JackM <no***@earthlin k.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;}$messa ge = $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($val ue))" does?

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

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

foreach($_POST as $key =$value){
if(is_array($va lue)){
$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***@earthlin k.netwrote:
Rik wrote:
> foreach($_POST as $key =value){
$message = $key . ': '.((is_array($v alue)? implode(',',$va lue):
$value);
}

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

foreach($_POST as $key =$value){
if(is_array($va lue)){
$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
2121
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 construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No...
2
8331
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 checkboxes like this: chk1 chk1 chk1 But I need to name them with an array for deletion purposes which is already coded and working - I need...
4
1675
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" border = "1"> <tr> <td> <input type = "checkbox" onClick = "alert('Row 1');"> </td>
0
2787
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 chkAll. I simply want to have chkAll be checked if every item in the repeater has its checkbox checked. In the code behind page, I can access the...
0
2262
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 chkAll. I simply want to have chkAll be checked if every item in the repeater has its checkbox checked. In the code behind page, I can access the...
45
4814
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 "new Array() vs " question or to the array performance, I dared to move it to a new thread. Gecko takes undefined value strictly as per Book 4,...
29
3128
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. Does each checkbox name have to be unique? I was hoping to just group them under one name, and select from that array. PHP is not my native...
0
4088
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 with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I...
0
3100
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td colspan="2"><p>
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.