Grow your CSS skills. Land your dream job.

How to send checkbox selections in a form to email

  • # October 17, 2012 at 7:23 am

    Hi, I am having issues capturing data from the checkboxes in my form. I can’t figure out what code needs to go into the php file for multiple selections.

    The rest of the form is fine so I have left out most of the coding. Below is my html code for the checkboxes and my full php code as it stands.

    Any guidance/code would be greatly aprpeciated. Thanks in advance!

    **HTML Code**

    Please select your preferred sessions:

    Morning: 10am – 1pm

    Afternoon: 2pm – 5pm

    Evening: 7pm – 10pm

    **PHP Code**
    < ?php

    $EmailFrom = “myemail@email.com”;
    $EmailTo = “myemail@email.com”;
    $Subject = “Registration;
    $Fullname = Trim(stripslashes($_POST));
    $Email = Trim(stripslashes($_POST));
    $Session = Trim(stripslashes($_POST));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print ““;
    exit;
    }

    // prepare email body text
    $Body = “”;
    $Body .= “Fullname: “;
    $Body .= $Fullname;
    $Body .= “n”;
    $Body .= “Email: “;
    $Body .= $Email;
    $Body .= “n”;
    $Body .= “Session: “;
    $Body .= $Session;
    $Body .= “n”;

    // send email
    $success = mail($EmailTo, $Subject, $Body, “From: < $EmailFrom>“);

    // redirect to success page
    if ($success){
    print ““;
    }
    else{
    print ““;
    }
    ?>

    # October 17, 2012 at 11:36 am

    Try putting the code in the given “Code” tag when posting. That post is a jumbled mess and I don’t even want to attempt to decipher it! :P

    # October 17, 2012 at 11:43 am

    Fixed some of it.

    # October 17, 2012 at 12:56 pm

    Checkbox’s return yes or no as a value. You would have to have 3 unique names for each checkbox and use PHP to see which returned YES or NO.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".