Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created March 19, 2020 01:31
Show Gist options
  • Save phpfiddle/19b4de4e391d1e430f7b3f787ee9fe31 to your computer and use it in GitHub Desktop.
Save phpfiddle/19b4de4e391d1e430f7b3f787ee9fe31 to your computer and use it in GitHub Desktop.
[ Posted by [email protected] ] PHP Date string from a HTML Form validation
<!DOCTYPE HTML>
<html>
<head>
<title>PHP Date string from a HTML Form validation</title>
</head>
<body>
<?php
// define variables and set to empty values
$birthdate = '';
if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) {
$birthdate = test_input( $_POST[ 'birthdate' ] );
echo '<h2>Your Input:</h2>';
echo $birthdate;
}
function test_input( $data ) {
$data = trim( $data );
$data = stripslashes( $data );
$data = htmlspecialchars( $data );
return $data;
}
?>
<h2>PHP Form Validation Example</h2>
<form method="post"
action="<?php
echo htmlspecialchars( $_SERVER[ 'PHP_SELF' ] );
?>">
Birthdate: <input type="date" name="birthdate" value="<?php echo date('Y-m-d', time()); ?>" /><br />
<input type="submit" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment