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 8392459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:31:32+00:00 2026-06-09T19:31:32+00:00

I have a form which I created using PHP (something I do no understand

  • 0

I have a form which I created using PHP (something I do no understand nearly as much as i’d like) – I made the form using an online tutorial a while back, cannot quite remember where from and can’t find it again, however the form works as it should so i’m content.

The only thing is, I need to add checkboxes to my form, they do not need to validate (if nothing is checked, the form can still be sent, if they are all checked the form can still be sent..)

What I do need to happen is for the e-mail that is sent back to me, to let me know which checkboxes were ticked.

This is my HTML/PHP page:

<!--Contact Form Section -->    
<div id="contact-form" class="clearfix">  

        <?php  
//init variables  
$cf = array();  
$sr = false;  

if(isset($_SESSION['cf_returndata'])){  
$cf = $_SESSION['cf_returndata'];  
$sr = true;  
}  
?>

<form method="post" action="process.php">  

    <input type="email" id="email" name="email" placeholder="Your e-mail" value="    <?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?>" required="required" />  

    <input type="text" id="name" name="name" placeholder="Your name" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>" required="required" />  

    <textarea id="message" name="message" placeholder="Your message..." required="required" data-minlength="20"><?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?></textarea>  

<span id="loading"></span>  
<input type="submit" value="&nbsp;" id="submit-button" /> 

    <ul id="errors" class="<?php echo ($sr && !$cf['form_ok']) ? 'visible' : ''; ?>">  
    <li id="info">There is a problem:</li>  
<?php  
if(isset($cf['errors']) && count($cf['errors']) > 0) :  
    foreach($cf['errors'] as $error) :  
?>  
    <li><?php echo $error ?></li>  
<?php  
    endforeach;  
endif;  
?>  
</ul>  

<p id="success" class="<?php echo ($sr && $cf['form_ok']) ? 'visible' : ''; ?>">Thanks for your message!</p>
</div>

</form>  
<?php unset($_SESSION['cf_returndata']); ?>   
<!--End Contact Form Section -->    

And here is my process PHP document:

<?php  
if( isset($_POST) ){  

//form validation vars  
$formok = true;  
$errors = array();  

//submission data  
$ipaddress = $_SERVER['REMOTE_ADDR'];  
$date = date('d/m/Y');  
$time = date('H:i:s');  

//form data  
$name = $_POST['name'];  
$email = $_POST['email'];  
$telephone = $_POST['telephone'];  
$enquiry = $_POST['enquiry'];  
$message = $_POST['message'];  

//validate form data  

//validate name is not empty  
if(empty($name)){  
    $formok = false;  
    $errors[] = "You have not entered a name";  
}  

//validate email address is not empty  
if(empty($email)){  
    $formok = false;  
    $errors[] = "You have not entered an email address";  
//validate email address is valid  
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){  
    $formok = false;  
    $errors[] = "You have not entered a valid email address";  
}  

//validate message is not empty  
if(empty($message)){  
    $formok = false;  
    $errors[] = "You have not entered a message";  
}  
//validate message is greater than 20 characters  
elseif(strlen($message) < 20){  
    $formok = false;  
    $errors[] = "Your message must be greater than 20 characters";  
}  

//send email if all is ok  
if($formok){  
    $headers = "From: Goldie Locks online contact form" . "\r\n";  
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

    $emailbody = "<p>You have received a new message from the enquiries form on your website.</p> 
                  <p><strong>Name: </strong> {$name} </p> 
                  <p><strong>Email Address: </strong> {$email} </p> 
                  <p><strong>Message: </strong> {$message} </p> 
                  <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";  

    mail("MY EMAIL!","New Enquiry",$emailbody,$headers);  

}  

//what we need to return back to our form  
$returndata = array(  
    'posted_form_data' => array(  
        'name' => $name,  
        'email' => $email,  
        'telephone' => $telephone,  
        'enquiry' => $enquiry,  
        'message' => $message  
    ),  
    'form_ok' => $formok,  
    'errors' => $errors  
);  

//if this is not an ajax request  
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&     strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){  
    //set session variables  
    session_start();  
    $_SESSION['cf_returndata'] = $returndata;  

    //redirect back to form  
    header('location: ' . $_SERVER['HTTP_REFERER']);  
}  
}

As you can see from looking at the html code, I took out some of the functions of the PHP but left them in the PHP process (such as enquiry type and telephone number) because I Was completely unsure what would break what.

All I need to do is add check boxes to the html/php document (5 to be precise) and have the ones that are ticked show up in the e-mail I receive when some one fills out the page.

Hopefully this is an easy thing for someone with PHP knowledge, but sadly I have very very little. Hope some one can help, if you need any more info please comment and i’ll try my best.

Thank you

  • 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-09T19:31:33+00:00Added an answer on June 9, 2026 at 7:31 pm

    you can add checkboxes to the form by simply adding a checkbox input element:

    <input type="checkbox" name"myCheckbox" value="true" />
    

    set the value="" to whatever you want. You can then pick up the value in your PHP script using:

    $myCheckbox = $_POST['myCheckbox'];
    

    The variable $myCheckbox will then contain the value of the checkbox with name ‘myCheckbox’ in the form if it was checked, or it’ll be blank if the checkbox was not checked.

    You can then add the value to the email as you have with the other variables, i.e.

    $emailbody = "<p>You have received a new message from the enquiries form on your website.</p> 
        <p><strong>Name: </strong> {$name} </p> 
        <p><strong>Email Address: </strong> {$email} </p> 
        <p><strong>Message: </strong> {$message} </p>
        <p><strong>myCheckbox value: </strong> {$myCheckbox}</p>
        <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
    

    If you wanted to keep the checked / not checked status on the form if it’s submitted and fails validation for whatever reason, then you can add the checkbox value to the $returndata variable:

    $returndata = array(
        'posted_form_data' => array(  
            'name' => $name,  
            'email' => $email,  
            'telephone' => $telephone,  
            'enquiry' => $enquiry,  
            'message' => $message,
            'myCheckbox' => $myCheckbox,
        ),  
        'form_ok' => $formok,  
        'errors' => $errors
    );
    

    This will send it back to the form and then you need to alter the checkbox to look for this value as the other elements do, and add a value of ‘checked=Checked”‘ to the checkbox if it was previously checked:

    <input type="checkbox" name"myCheckbox" value="true" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['myCheckbox]=="true") ? 'checked="checked"' : '' ?> />
    

    where the true part of the line $cf['posted_form_data']['myCheckbox]=="true" is the value="" value of the checkbox.

    I hope that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a PHP form which requires the user to select a postcode
I have created a user registration form using PHP, a password must be entered
I have created a PHP form, which, upon submission, goes to another PHP page.
I have a form with multiple textboxes which are created dynamically, now all these
I have created one jsp form which contains the username textfield. On the click
I have created a form on which two components are present, button and progressbar
I have a form created in Windows Forms which is draggable wherever I click.
I have created a form for my news articles which I then call to
I've created an app which contains form and that have to filled up in
I have created a macro for excel which will pop up form that contains

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.