Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:11:38+00:00 2026-06-15T20:11:38+00:00

I have a simple example of check box’s which remember what has been selected

  • 0

I have a simple example of check box’s which remember what has been selected after the form has been submitted and there is an error.

That part works great… but, I would like to post the resultant ‘checked’ boxes to my forms mail function.

What I have now only reports if its checked or unchecked I would prefer to have the checked box’s ‘value’ without the unchecked box even registering.

<?php

$CB_1 = 'unchecked';
$CB_2 = 'unchecked';
$CB_3 = 'unchecked';
$CB_4 = 'unchecked';
$CB_5 = 'unchecked';

if (isset($_POST['submit'])) {

if (isset($_POST['CB_1'])) {$CB_1 = $_POST['CB_1'];
if ($CB_1 == 'item_01') {$CB_1 = 'checked';}
}

if (isset($_POST['CB_2'])) {$CB_2 = $_POST['CB_2'];
if ($CB_2 == 'item_02') {$CB_2 = 'checked';}
}

if (isset($_POST['CB_3'])) {$CB_3 = $_POST['CB_3'];
if ($CB_3 == 'item_03') {$CB_3 = 'checked';}
}

if (isset($_POST['CB_4'])) {$CB_4 = $_POST['CB_4'];
if ($CB_4 == 'item_04') {$CB_4 = 'checked';}
}

if (isset($_POST['CB_5'])) {$CB_5 = $_POST['CB_5'];
if ($CB_5 == 'item_05') {$CB_5 = 'checked';}
}
}

if (isset($_POST['submit'])) {
$error  = "";

    if (!empty($_POST['email'])) {
    $email = $_POST['email'];

    if (!preg_match("/^[a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){ 
    $error .= "E-mail address not valid.";
    }

    } else {

    $error .= "E-mail address is required.";
    }

    if (empty($error)) {

    $from = 'From: '. @TEST .' <'. $email .'>';
    $to = "someone@company.com";
    $subject = "CHECKBOX TEST";
    $content = "

    checkbox selections: 
                        check box 01: $CB_1
                        check box 02: $CB_2
                        check box 03: $CB_3
                        check box 04: $CB_4
                        check box 05: $CB_5

    ";

    $success = mail($to,$subject,$content,$from);
    }
    }

?>



<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">

<?php if (!empty($error)) echo $error ?>

<br><br><br>

e-mail: <input type="text" name="email" value="<?php if (isset ($_POST {'email'})) { echo $_POST['email']; } ?>" />

<P>

<input type="checkbox" name="CB_1" value="item_01" <?PHP echo $CB_1; ?> /> Item 01 

<input type="checkbox" name="CB_2" value="item_02" <?PHP echo $CB_2; ?> /> Item 02 

<input type="checkbox" name="CB_3" value="item_03" <?PHP echo $CB_3; ?> /> Item 03 

<input type="checkbox" name="CB_4" value="item_04" <?PHP echo $CB_4; ?> /> Item 04 

<input type="checkbox" name="CB_5" value="item_05" <?PHP echo $CB_5; ?> /> Item 05 

<P>

<input type="submit" name="submit" value="Submit"></input>

</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:11:39+00:00Added an answer on June 15, 2026 at 8:11 pm

    I found what I was looking for I suppose in the way of an array which I think ‘redelman431’ was trying to get me to do but it didn’t make any sense to me at the time.

    I then stumbled onto another array by ‘David Bélanger’ that for some reason made more sense to me so I used it into my check box’s and it works fabulously.

    the new problem is that I cant get the check box’s that have been checked to remember that if there is an error elsewhere on the page which is a disaster as my final form has a ton of them.

    Any ideas?

    <?php
    
        #   Default Vars
        $_group_01 = '';
        if(isset($group_01) === TRUE){
        #   Is Array ?
        if(is_array($group_01) === TRUE){
        #   Count
        $c = count($group_01);
        #   Loop
        for($i=0; $i < $c; $i++){
        $_group_01.= (isset($group_01[$i]) === TRUE ? $group_01[$i] : '').($i == ($c-1) ? '' : ($i == $c-2 ? ' and ' : ', '));
        }
        }
        }
    
    if (isset($_POST['submit'])) {
    $error  = "";
    
        if (!empty($_POST['email'])) {
        $email = $_POST['email'];
    
        if (!preg_match("/^[a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){ 
        $error .= "E-mail address not valid.";
        }
    
        } else {
    
        $error .= "E-mail address is required.";
        }
    
        if (empty($error)) {
    
        $from = 'From: '. TEST .' <'. $email .'>';
        $to = "someone@company.com";
        $subject = "CHECKBOX TEST";
        $content = "
    
    checkbox selections: 
    
    Items Checked: $_group_01
    
        ";
    
        $success = mail($to,$subject,$content,$from);
        }
        }
    
    ?>
    
    
    
    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
    
    <span style="color: red;"><?php if (!empty($error)) echo $error ?></span>
    
    <br><br><br>
    
    e-mail: <input type="text" name="email" value="<?php if (isset ($_POST {'email'})) { echo $_POST['email']; } ?>" />
    
    
    
    <P>
    
    <input type="checkbox" name="group_01[]" value="Item 01" 
    <?php if(isset($_POST['group_01'])) { echo 'checked'; } ?> />Item 01
    
    <input type="checkbox" name="group_01[]" value="Item 02" 
    <?php if(isset($_POST['group_01'])) { echo 'checked'; } ?> />Item 02
    
    <input type="checkbox" name="group_01[]" value="Item 03" 
    <?php if(isset($_POST['group_01'])) { echo 'checked'; } ?> />Item 03
    
    <input type="checkbox" name="group_01[]" value="Item 04" 
    <?php if(isset($_POST['group_01'])) { echo 'checked'; } ?> />Item 04
    
    <input type="checkbox" name="group_01[]" value="Item 05" 
    <?php if(isset($_POST['group_01'])) { echo 'checked'; } ?> />Item 05
    
    <P>
    
    
    
    <input type="submit" name="submit" value="Submit"></input>
    
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple program that checks webpages for strings, example: Private Sub Button1_Click(ByVal
I have this simple example I can't seems to get working : MERGE INTO
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I have a simple example ( SVG source ) looks like you can see
so I have a simple example--a fully crossed three treatment three context experiment, where
Does anyone have a simple example of implementing an async validation rule in csla?
I have a very simple example. A button on the bottom of the screen
I have this very simple example that I am using to learn structs in
A simple example: Let's say I have one alias being sourced somewhere as: alias
Have a look a this simple example. I don't quite understand why o1 prints

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.