<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title><?php if ( $_POST ) { echo( "Results - " ) ; } ?>All Form Input Types</title>

  <style>
    .inputhtml
    {
    }

    .forminput
    {
    }

    .forminput input
    {
    }
  </style>
</head>
<body>
<?php

// Get current date and time settings

date_default_timezone_set( "America/Toronto" ) ;

$date = strftime( "%F" ) ;
$time = strftime( "%R" ) ;


// http://www.w3schools.com/tags/tag_input.asp
// http://www.w3schools.com/tags/att_input_type.asp

$INPUT_TYPES =
array(
    "button" => "input_button",
    "checkbox" => "input_checkbox",
    "color" => "input_color",
    "date" => "input_date",
    "datetime" => "input_datetime",
    "datetime-local" => "input_datetimelocal",
    "email" => "input_email",
    "file" => "input_file",
    "hidden" => "input_hidden",
    "image" => "input_image",
    "month" => "input_month",
    "number" => "input_number",
    "password" => "input_password",
    "radio" => "input_radio",
    "range" => "input_range",
    "reset" => "input_reset",
    "search" => "input_search",
    "submit" => "input_submit",
    "tel" => "input_tel",
    "text" => "input_text",
    "time" => "input_time",
    "url" => "input_url",
    "week" => "input_week",
) ;

function
input_button( $name, $args = NULL )
{
    $html = "<input type=\"button\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
        if ( array_key_exists( 'alert', $args ) )
        {
            $html .= " onClick=\"alert( 'Button \'" . $name .
                "\' clicked' );\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_checkbox( $name, $args = NULL )
{
    $html = "<input type=\"checkbox\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
        if ( array_key_exists( 'checked', $args ) )
        {
            $html .= " checked=\"checked\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_color( $name, $args = NULL )
{
    $html = "<input type=\"color\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_date( $name, $args = NULL )
{
    $html = "<input type=\"date\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_datetime( $name, $args = NULL )
{
    $html = "<input type=\"datetime\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_datetimelocal( $name, $args = NULL )
{
    $html = "<input type=\"datetime-local\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_email( $name, $args = NULL )
{
    $html = "<input type=\"email\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_file( $name, $args = NULL )
{
    $html = "<input type=\"file\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_hidden( $name, $args = NULL )
{
    $html = "<input type=\"hidden\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_image( $name, $args = NULL )
{
    $html = "<input type=\"image\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
        if ( array_key_exists( 'src', $args ) )
        {
            $html .= " src=\"" . $args[ 'src' ] . "\"" ;
        }
        if ( array_key_exists( 'alt', $args ) )
        {
            $html .= " alt=\"" . $args[ 'alt' ] . "\"" ;
        }
        if ( array_key_exists( 'width', $args ) )
        {
            $html .= " width=\"" . $args[ 'width' ] . "\"" ;
        }
        if ( array_key_exists( 'height', $args ) )
        {
            $html .= " height=\"" . $args[ 'height' ] . "\"" ;
        }
        if ( array_key_exists( 'alert', $args ) )
        {
            $html .= " onClick=\"alert( 'Image \'" . $name .
                "\' clicked' );\"" ;
        }
        if ( array_key_exists( 'formaction', $args ) )
        {
            $html .= " formaction=\"" .
                $args[ 'formaction' ] . "\"" ;
        }
        if ( array_key_exists( 'formmethod', $args ) )
        {
            $html .= " formmethod=\"" .
                $args[ 'formmethod' ] . "\"" ;
        }
        if ( array_key_exists( 'formtarget', $args ) )
        {
            $html .= " formtarget=\"" .
                $args[ 'formtarget' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_month( $name, $args = NULL )
{
    $html = "<input type=\"month\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_number( $name, $args = NULL )
{
    $html = "<input type=\"number\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
        if ( array_key_exists( 'min', $args ) )
        {
            $html .= " min=\"" . $args[ 'min' ] . "\"" ;
        }
        if ( array_key_exists( 'max', $args ) )
        {
            $html .= " max=\"" . $args[ 'max' ] . "\"" ;
        }
        if ( array_key_exists( 'step', $args ) )
        {
            $html .= " step=\"" . $args[ 'step' ] . "\"" ;
        }
        if ( array_key_exists( 'placeholder', $args ) )
        {
            $html .= " placeholder=\"" .
                $args[ 'placeholder' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_password( $name, $args = NULL )
{
    $html = "<input type=\"password\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_radio( $name, $args = NULL )
{
    $html = "<input type=\"radio\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
        if ( array_key_exists( 'checked', $args ) )
        {
            $html .= " checked=\"checked\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_range( $name, $args = NULL )
{
    $html = "<input type=\"range\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
        if ( array_key_exists( 'min', $args ) )
        {
            $html .= " min=\"" . $args[ 'min' ] . "\"" ;
        }
        if ( array_key_exists( 'max', $args ) )
        {
            $html .= " max=\"" . $args[ 'max' ] . "\"" ;
        }
        if ( array_key_exists( 'step', $args ) )
        {
            $html .= " step=\"" . $args[ 'step' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_reset( $name, $args = NULL )
{
    $html = "<input type=\"reset\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_search( $name, $args = NULL )
{
    $html = "<input type=\"search\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_submit( $name, $args = NULL )
{
    $html = "<input type=\"submit\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_tel( $name, $args = NULL )
{
    $html = "<input type=\"tel\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_text( $name, $args = NULL )
{
    $html = "<input type=\"text\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_time( $name, $args = NULL )
{
    $html = "<input type=\"time\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_url( $name, $args = NULL )
{
    $html = "<input type=\"url\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
input_week( $name, $args = NULL )
{
    $html = "<input type=\"week\" name=\"" . $name . "\"" ;
    if ( isset( $args ) )
    {
        if ( array_key_exists( 'value', $args ) )
        {
            $html .= " value=\"" . $args[ 'value' ] . "\"" ;
        }
    }
    $html .= ">" ;
    return $html ;
}

function
printtag( $name, $htmlfunc )
{
    global $encoded ;

    if ( array_key_exists( $name, $_POST ) )
    {
        $cooked = $_POST[ $name ] ;
        $raw = $encoded[ $name ] ;
        $cookedlength = strlen( $cooked );
        $rawlength = strlen( $raw ) ;
    }
    else
    {
        $cooked = $raw = NULL ;
        $cookedlength = $rawlength = 0 ;
    }
?>
<h2><?php echo( $name ) ; ?></h2>
<p>Form tag:</p>
<?php
$html = $htmlfunc( $name ) ;
?>
<pre><?php echo( htmlentities( $html ) ) ; ?></pre>

<p>Encoded value (<?php echo( $rawlength ); ?> bytes):</p>
<?php
    if ( ! is_null( $raw ) )
    {
        if ( $rawlength > 0 )
        {
?>
<pre><?php echo( $raw ) ; ?></pre>
<?php
        }
        else
        {
?>
<p><em>Empty</em></p>
<?php
        }
    }
    else
    {
?>
<p><em>Undefined</em></p>
<?php
    }
?>
<hr>
<p>Decoded value (<?php echo( $cookedlength ); ?> bytes):</p>
<?php
    if ( ! is_null( $cooked ) )
    {
        if ( $cookedlength > 0 )
        {
?>
<pre><?php echo( $cooked ) ; ?></pre>
<?php
        }
        else
        {
?>
<p><em>Empty</em></p>
<?php
        }
    }
    else
    {
?>
<p><em>Undefined</em></p>
<?php
    }
?>
<hr>
<?php
}

if ( $_POST )
{
?>
<h1>Form Content</h1>

<h2>Raw Form Data</h2>

<pre><?php $rawdata = file_get_contents( "php://input" ) ;
echo( $rawdata ) ?></pre>

<p>Content length: <?php printf( "%d bytes",
 $_SERVER[ 'CONTENT_LENGTH' ] ) ; ?></p>

<?php

$kvps = preg_split( "/\&/", $rawdata ) ;
$encoded = array( ) ;

foreach ( $kvps as $kv )
{
    list( $key, $value ) = preg_split( "/=/", $kv ) ;
    $encoded[ $key ] = $value ;
}

$keys = array_keys( $INPUT_TYPES ) ;

sort( $keys ) ;

foreach ( $keys as $key )
{
    $name = $key . "_in" ;
    printtag( $name, $INPUT_TYPES[ $key ] ) ;
}

}
else    // GET
{
?>
<form method="post" action="<?php echo( $_SERVER[ 'PHP_SELF' ] ) ; ?>">
<?php

// button

$button_args = array(
    "value" => "Click here",
    "alert" => "true"
) ;

$button_html = input_button( "button_in", $button_args ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $button_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">button &mdash; " . $button_html . "</p>\n\n" ) ;


// checkbox

$checkbox_args = array(
    "checked" => "true"
) ;

$checkbox_html = input_checkbox( "checkbox_in", $checkbox_args ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $checkbox_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">checkbox &mdash; " . $checkbox_html . "</p>\n\n" ) ;


// color

$color_html = input_color( "color_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $color_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">color &mdash; " . $color_html . "</p>\n\n" ) ;


// date

$date_html = input_date( "date_in", array( "value" => $date ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $date_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">date &mdash; " . $date_html . "</p>\n\n" ) ;


// datetime

// $datetime = $date . " " . $time ;
$datetime = date( DateTime::ATOM ) ;

$datetime_html = input_datetime( "datetime_in",
    array( "value" => $datetime ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $datetime_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">datetime &mdash; " . $datetime_html . "</p>\n\n" ) ;


// datetime-local

/*
 *  From http://www.w3schools.com/jsref/prop_datetime_value.asp
 *
 *  YYYY-MM-DDThh:mm:ssTZD 
 *  Specifies the date and/or time. Explanation of components:
 *
 *   YYYY - year (e.g. 2011)
 *    MM - month (e.g. 01 for January)
 *    DD - day of the month (e.g. 08)
 *    T - a required separator if time is also specified
 *    hh - hour (e.g. 22 for 10.00pm)
 *    mm - minutes (e.g. 55)
 *    ss - seconds (e.g. 03)
 *    TZD - Time Zone Designator (Z denotes Zulu, also known as
 *    Greenwich Mean Time)
 */

//$datetime = date( "c" ) ;

/*  https://stackoverflow.com/questions/10854874/
 *    input-type-datetime-value-format
 *
 * <p>
 * <input type="datetime" name="somedatafield" value="2011-12-21T11:33:23Z">
 * </p>
 */

$datetime_local = $date . "T" . $time ;

$datetimelocal_html = input_datetimelocal( "datetimelocal_in",
    array( "value" => $datetime_local ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $datetimelocal_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">datetime-local &mdash; " . $datetimelocal_html . "</p>\n\n" ) ;


// email

$email_html = input_email( "email_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $email_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">email &mdash; " . $email_html . "</p>\n\n" ) ;


// file

$file_html = input_file( "file_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $file_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">file &mdash; " . $file_html . "</p>\n\n" ) ;


// hidden

$hidden_html = input_hidden( "hidden_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $hidden_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">hidden &mdash; " . $hidden_html . "</p>\n\n" ) ;


// image

$image_details = array(
    "src"        =>    "social-icons-large.png",
    "alt"        =>    "Social Media",
    "width"        =>    "105",
    "height"    =>    "35",
    "alert"        =>    "true",
    "formaction"    =>    "socialmedia.php",
    "formmethod"    =>    "get",
    "formtarget"    =>    "_blank"
) ;

$image_html = input_image( "image_in", $image_details ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $image_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">image &mdash; " . $image_html . "</p>\n\n" ) ;


// month

// http://www.w3schools.com/jsref/prop_month_value.asp

$month = strftime( "%Y-%m" ) ;

$month_html = input_month( "month_in", array( "value" => $month ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $month_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">month &mdash; " . $month_html . "</p>\n\n" ) ;


// number

$number_args = array(
    "min"        =>    "1",
    "max"        =>    "10",
    "step"        =>    "1",
    "value"        =>    "8"
    /* "placeholder"    =>    "Rate from 1 to 10" */
) ;

$number_html = input_number( "number_in", $number_args ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $number_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">number &mdash; " . $number_html . "</p>\n\n" ) ;


// password

$password_html = input_password( "password_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $password_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">password &mdash; " . $password_html . "</p>\n\n" ) ;


// radio

$radio_args = array(
    "checked" => "true"
) ;

$radio_html = input_radio( "radio_in", $radio_args ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $radio_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">radio &mdash; " . $radio_html . "</p>\n\n" ) ;


// range

$range_args = array(
    "min"    =>    "0",
    "max"    =>    "100",
    "step"    =>    "10",
    "value"    =>    "80"
) ;

$range_html = input_range( "range_in", $range_args ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $range_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">range &mdash; " . $range_html . "</p>\n\n" ) ;


// search

$search_html = input_search( "search_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $search_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">search &mdash; " . $search_html . "</p>\n\n" ) ;


// tel

$tel_html = input_tel( "tel_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $tel_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">tel &mdash; " . $tel_html . "</p>\n\n" ) ;


// text

$text_html = input_text( "text_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $text_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">text &mdash; " . $text_html . "</p>\n\n" ) ;


// time

$time = strftime( "%R" ) ;

$time_html = input_time( "time_in", array( "value" => $time ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $time_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">time &mdash; " . $time_html . "</p>\n\n" ) ;


// url

$url_html = input_url( "url_in" ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $url_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">url &mdash; " . $url_html . "</p>\n\n" ) ;


// week

// http://www.w3schools.com/jsref/prop_week_value.asp

$week = strftime( "%Y-W%W" ) ;

$week_html = input_week( "week_in", array( "value" => $week ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $week_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">week &mdash; " . $week_html . "</p>\n\n" ) ;


// reset

$reset_html = input_reset( "reset_in", array( "value" => "Reset Form" ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $reset_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">reset &mdash; " . $reset_html . "</p>\n\n" ) ;


// submit

$submit_html = input_submit( "submit_in", array( "value" => "Send Form" ) ) ;

echo( "<pre class=\"htmltag\">\n" . htmlentities( $submit_html ) . "\n</pre>\n\n" ) ;

echo( "<p class=\"forminput\">submit &mdash; " . $submit_html . "</p>\n\n" ) ;


?>
</form>
<?php
} // endif ( POST|GET )
?>
</body>
</html>