Created
March 19, 2020 01:31
-
-
Save phpfiddle/19b4de4e391d1e430f7b3f787ee9fe31 to your computer and use it in GitHub Desktop.
[ Posted by [email protected] ] PHP Date string from a HTML Form validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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