samedi 23 mai 2015

PHP Multiple Checkbox Array Not Sending All Values

I read over some questions on Stackoverflow but none of them solved my issue, but maybe I just overlooked something because I lack proficiency in PHP.

I know the form code is correct, but there is something wrong in my PHP because only the last element of the checkboxes gets sent upon completion of the form.

I'm not asking for a solution, I just need a kick in the right direction so I know what I am doing wrong.

Sorry, I am not familiar with back end so this is a learning process for me.

Thanks!

Here is the PHP (changed email for privacy):

<?php
    if ($_POST["submit"]) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $company = $_POST['company'];
        $website = $_POST['website'];
        $checkboxes = $_POST['checkboxvar'];
           foreach ($checkboxes as $checkboxes=>$value) {
                     $value."\n";
                }
        $timeframe = $_POST['timeframe'];
        $description = $_POST['description'];
        $to = 'example@example.com'; 
        $subject = 'Full Contact Form';

        $body ="Name: $name\n\n
        E-Mail: $email\n\n 
        Phone: $phone\n\n 
        Company: $company\n\n 
        Website: $website\n\n 
        Checkboxes: $value\n
        Time Frame: $timeframe\n\n 
        Project Description:\n\n $description";

        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }

        if (!$_POST['description']) {
            $errDescription = 'Please enter your project description';
        }

if (!$errName && !$errEmail && !$errDescription) {
    if (mail ($to, $subject, $body)) {
        $result='<div class="alert alert-success alert-success-full-contact">Your request has been sent!</div>';
    } else {
        $result='<div class="alert alert-danger alert-danger-full-contact">Sorry, there was an error. Try again later!</div>';
    }
}
    }
?>




Aucun commentaire:

Enregistrer un commentaire