How to handle HTML checkboxes with PHP

<?php

//Set "terms accepted" to false by default.
$termsAccepted = false;

//If the POST variable "terms_of_service" exists.
if(isset($_POST['terms_of_service'])){
    //Checkbox has been ticked.
    $termsAccepted = true;
}

//Print it out for example purposes.
if($termsAccepted){
    echo 'Terms of Service checkbox ticked!';
}

?>

<form action="" method="post">
    <label>
        I accept the terms of service.
        <input type="checkbox" name="terms_of_service" value="Y">
    </label>
    <input type="submit" value="Register">
</form>

 

How to choose a random word from an array php
<?php $Words =array("Black","Yellow","Blue","Red","Purple","Pink", "White"); $rand_word=array_rand($Words,2); $Result =
How to minify HTML code of PHP page
<?php ob_start("minifier"); function minifier($code) { $search =
How to copy a file from one directory to another using PHP
<?php // Copy the file from /user/desktop/geek.txt
How to Deleting all files from a folder using PHP
<?php // PHP program to delete all
How do I test if an remote image file exists in php
if(@get_headers($your_url) == 'HTTP/1.1 404 Not Found') {
Human Readable File Size with PHP
function bytesToHuman($bytes) { $units = ['B', 'KB',
PHP Simple File Upload from Remote URL
<?php if($_POST){ //get the url $url =
PHP unzipper / extracts .zip archives and .gz files on webservers
<?php $timestart = microtime(TRUE); $arc = new
Get the first character in a string with PHP
//Example string. $string = "My milkshake brings
How to generate a random token with PHP
//Generate a random string. $token = openssl_random_pseudo_bytes(16);
Generating random names with PHP
<?php //PHP array containing forenames. $names =
How to create PHP Timer Countdown
//You must call the function session_start() before
PHP – Do not echo out HTML!
Wrong: <?php echo '<div id="user_profile">'; echo '<h1>'
How to rotate a series of words on page load using PHP
$words = array('fox', 'hippo', 'dog', 'cat'); echo
How to check if a value exists in an array in PHP
$zoo = array("Lion", "Elephant", "Tiger", "Zebra", "Rhino",
How to Get the Current Date and Time in PHP
date_default_timezone_set('Asia/Kolkata'); $date = date('d-m-y h:i:s'); echo $date;
How to remove HTML special characters from a string in PHP
$my_str = "String with <b>special</b> characters."; //
How to extract substring from a string in PHP
$str = "Hello World!"; echo substr($str, 0,
How to Get Current Page URL in PHP
PHP program to get complete URL of

Top