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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:57:51+00:00 2026-06-02T20:57:51+00:00

I need to check that the check box is checked (required) and need the

  • 0

I need to check that the check box is checked (required) and need the validation to perform much like the other form fields, and then i need to post the value in email.

PHP for entire form as it stands:

<?php
if(isset($_POST['formtrigger'])):

    //config
    define('FORM_SENDTO','hello@domain.com');
    define('FORM_SUBJECTLINE','Enquiry from website');
    define('ERR_MSG_FIELD_REQUIRED','This field is required.');
    define('ERR_MSG_FIELD_INVALIDEMAIL','Please enter a valid email address.');

    //setup validation rules

        //Name
        $validation_rules['forename']['required'] = true;
        $validation_rules['surname']['required'] = true;

        //Company
        $validation_rules['company']['required'] = true;

        //Address
        $validation_rules['address']['required'] = true;

        //Tel
        $validation_rules['tel']['required'] = true;

        //Email
        $validation_rules['email']['required'] = true;
        $validation_rules['email']['valid_email'] = true;

        //Enquiry
        $validation_rules['enquiry']['required'] = true;

        //title/gender
        $validation_rules['ts1']['required'] = true;

        $validation_rules['ts2']['required'] = true;

    //validate the form
    $formerrors=0;
    foreach($_POST as $formfield_name=>$formfield_value):

        //set the entered value as a sanitised string
        $_POST_SANITISED[$formfield_name] = filter_var($formfield_value,FILTER_SANITIZE_STRING);

        //Check if required
        if($validation_rules[$formfield_name]['required']):
            if(!strlen($formfield_value)>0):
                $formerrors++;
                $fielderrors[$formfield_name][] = ERR_MSG_FIELD_REQUIRED;
            endif;
        endif;

        //Check if valid email required
        if($validation_rules[$formfield_name]['valid_email']):
            if(!filter_var($formfield_value,FILTER_VALIDATE_EMAIL)):
                $formerrors++;
                $fielderrors[$formfield_name][] = ERR_MSG_FIELD_INVALIDEMAIL;
            endif;
        endif;

    endforeach;

    //process form and send message if validation passed
    if($formerrors==0):
        $email_msg[] = "New general enquiry\n\n-----------\n";
        $email_msg[] = "Title: ".$_POST_SANITISED['ts1']."\n";
        $email_msg[] = "Gender: ".$_POST_SANITISED['ts2']."\n";
        $email_msg[] = "Forename: ".$_POST_SANITISED['forename']."\n";
        $email_msg[] = "Surname: ".$_POST_SANITISED['surname']."\n";
        $email_msg[] = "Company: ".$_POST_SANITISED['company']."\n";
        $email_msg[] = "Address: ".$_POST_SANITISED['address']."\n";
        $email_msg[] = "Telephone No.: ".$_POST_SANITISED['tel']."\n";
        $email_msg[] = "Email: ".$_POST_SANITISED['email']."\n";
        $email_msg[] = "Enquiry: ".$_POST_SANITISED['enquiry']."\n";

        $email_msg[] = "-----------\n";

        $email_msg = implode('',$email_msg);

        $email_headers = 'From: ' . $_POST_SANITISED['email'] . "\r\n" .
        'Reply-To: ' . $_POST_SANITISED['email'] . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

        mail(FORM_SENDTO,FORM_SUBJECTLINE,$email_msg,$email_headers);

        header('Location: ?msgsent=1#thanks');

    endif;

endif;

function errorOutput($fieldname=''){
    global $fielderrors;
    if(count($fielderrors[$fieldname])>0):
        foreach($fielderrors[$fieldname] as $err_msg):
            $error_str .= '<div class="form-fielderror-msg">'.$err_msg.'</div>';
        endforeach;
    endif;
    return $error_str ? $error_str : false;
}

function errorClass($fieldname=''){
    global $fielderrors;
    $error_class = '';
    if(count($fielderrors[$fieldname])>0):
       $error_class = 'form-fielderror';
    endif;
    return $error_class ? $error_class : false;
}

?>

Here is the HTML:

        <?php if($_GET['msgsent']==1): ?>

    <h1>Thanks for your enquiry. If requested, we will get in touch shortly.</h1>

    <?php else: ?>


    <div id="form-cont">

        <form action="<?=$_SERVER['PHP_SELF']?>" method="post">



            <div class="form-element">
                <label for="ts1">Title:*</label>
                <select name="ts1" class="<?=errorClass('ts1')?>">
                        <option value="">-- Please select --</option>
                        <option value="Mr" <?=$_POST['ts1']=='Mr' ? 'selected="selected"' : '' ?>>Mr</option>
                        <option value="Mrs" <?=$_POST['ts1']=='Mrs' ? 'selected="selected"' : '' ?>>Mrs</option>
                        <option value="Miss" <?=$_POST['ts1']=='Miss' ? 'selected="selected"' : '' ?>>Miss</option>
                        <option value="Ms" <?=$_POST['ts1']=='Ms' ? 'selected="selected"' : '' ?>>Ms</option>
                </select>
                <?=errorOutput('ts1')?>
            </div>

            <div class="form-element">
                <label for="ts2">Gender:*</label>
                <select name="ts2" class="<?=errorClass('ts2')?>">
                        <option value="">-- Please select --</option>
                        <option value="Male" <?=$_POST['ts2']=='Male' ? 'selected="selected"' : '' ?>>Male</option>
                        <option value="Female" <?=$_POST['ts2']=='Female' ? 'selected="selected"' : '' ?>>Female</option>
                </select>
                <?=errorOutput('ts2')?>
            </div>      

            <div class="form-element">
                <label for="forename">Forename:*</label>
                <input type="text" name="forename" class="textbox <?=errorClass('forename')?>" value="<?=$_POST['forename']?>" />
                <?=errorOutput('forename')?>
            </div>

            <div class="form-element">
                <label for="surname">Surname:*</label>
                <input type="text" name="surname" class="textbox <?=errorClass('surname')?>" value="<?=$_POST['surname']?>" />
                <?=errorOutput('surname')?>
            </div>

            <div class="form-element">
                <label for="company">Company:*</label>
                <input type="text" name="company" class="textbox <?=errorClass('company')?>" value="<?=$_POST['company']?>" />
                <?=errorOutput('company')?>
            </div>

            <div class="form-element">
                <label for="address">Address:*</label>
                <input type="text" name="address" class="textbox <?=errorClass('address')?>" value="<?=$_POST['address']?>" />
                <?=errorOutput('address')?>
            </div>

            <div class="form-element">
                <label for="tel">Telephone No:*</label>
                <input type="text" name="tel" class="textbox <?=errorClass('tel')?>" value="<?=$_POST['tel']?>" />
                <?=errorOutput('tel')?>
            </div>

            <div class="form-element">
                <label for="email">Email:*</label>
                <input type="text" name="email" class="textbox <?=errorClass('email')?>" value="<?=$_POST['email']?>" />
                <?=errorOutput('email')?>
            </div>  

            <div class="form-element">
                <label for="enquiry">Your Enquiry:*</label>
                <textarea name="enquiry" class="<?=errorClass('enquiry')?>"><?=$_POST['enquiry']?></textarea>
                <?=errorOutput('enquiry')?>
            </div>      

            <div class="form-element">
                <label for="terms">Terms and Conditions</label>
                <input type="checkbox" name="terms" class="checkbox <?=errorClass('terms')?>" value="<?=$_POST['terms']=1?>" />
                <?=errorOutput('terms')?>
            </div>      

            <div class="form-element">
            <p class="clear">* denotes required field.</p>
            <input type="submit" class="submit" name="submit" value="Send" alt="Submit" title="Submit" />
            </div>
            <input type="hidden" name="formtrigger" value="1" />
        </form>

    </div>
    <?php endif ?>  

The checkbox in question as at the bottom:

<div class="form-element">
            <label for="terms">Terms and Conditions</label>
            <input type="checkbox" name="terms" class="checkbox <?=errorClass('terms')?>" value="<?=$_POST['terms']=1?>" />
            <?=errorOutput('terms')?>
        </div> 

Many thanks for you help! 🙂

  • 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-02T20:57:53+00:00Added an answer on June 2, 2026 at 8:57 pm
    if (isset($_POST['terms']))
    {
        // checked
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a checkbox when user checked that check box means. I need to
I have a check box that will if checked send a gift as a
I need to check that a string takes on the format 05:31:2008:06:27:2010 I do
I need an simple way to check whether a string that is sent to
I have a codeigniter form that contains two checkboxes: <input type=checkbox checked=checked id=box1 name=box1
I need a jquery script section that checks to see if the first digit
I need to create a javascript function that checks if it has been a
I need to make something(i call it a scheduler) that checks the time of
I want to (need to) start a sub-process from a perl script that checks
I need to create a function that receives a string and checks if the

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.