checkbox not returning selection info

I have a simple form that I made, for an outgoing email. In it is a checkbox for a destination $location. The location checkboxes are grouped together and php is using the following to give it initial value:
$location = isset($location) ? $location: array(‘None selected’);
Afterward, I’m using:
$destination = implode(’,’$location)
in order to display a success message.

The code appears to work, as far as checking for input. However, upon success, the form replies “Your message has been sent to None selected”. So, to be clear, $location seems to not return a true value.

Below, I’ve include the code that I think is pertinent. Please help if you can:
[php]<?php //sql connect. sql not pertinent to this question;
//process email
//if missing, add to $missing
$missing = array();

//process variables
$location = isset($location) ? $location: array(‘None selected’);
if ($_POST && empty($_POST[‘location’])) {
$mailSent = false;
array_push($missing, $location);
echo “

PLEASE SELECT A LOCATION

”;
}

$message = $_POST[‘message’];
if ($_POST && empty($_POST[‘message’])) {
$mailSent = false;
array_push($missing, $message);
echo “

THERE IS NO MESSAGE TO SEND.

”;
}
$destination = implode(’,’,$location);

//send it
if ($_POST && empty($missing)) {
$mailSent = mail($to, $subject, $message, $additionalHeaders);
}
}
?>

Mailing List

<?php if ($_POST && $mailSent) { echo "

Your message has been sent to $destination.

"; unset($missing); } ?> SEND TO:
checked = "checked" <?php } ?>/> Austin Area
checked = "checked" <?php } ?> /> DFW Area [/php]

You know, I’ve never ever been able to get a response on a forum. That’s okay. I’ve figured it out.

I changed:
[php]$location = isset($location) ? $location: array(‘None selected’);[/php]
to:
[php]
if(!isset($_POST[‘location’])) {
$_POST[‘location’] = array();
echo “

PLEASE SELECT A LOCATION

”;
}
else {
$location = implode(’,’,$_POST[‘location’]);
}[/php]
Then, I changed the success response to echo $location.

Next, I figure out how to loop a foreach statement, so that my response will be something like “Your message has been sent to Place1 and Place2”, rather than “Your message has been sent to Place1,Place2” as the array reads for now. Any pointers would be great! :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service