Skip to content

Instantly share code, notes, and snippets.

@kevinkhill
Created September 26, 2015 23:39
Show Gist options
  • Save kevinkhill/37e14375e8b19f81b850 to your computer and use it in GitHub Desktop.
Save kevinkhill/37e14375e8b19f81b850 to your computer and use it in GitHub Desktop.
PHP Forms Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Post Example</title>
<style type="text/css" rel="stylesheet">
html, body {
padding: 0;
margin: 0;
}
.center {
width: 100%;
background-color: skyblue;
margin-top: 200px;
text-align: center;
}
.center h1 {
font-size: 36pt;
}
</style>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="first_name">Input Name</label>
<input type="text" name="first_name" />
<input type="submit" value="Say Hi" />
<br />
<input type="radio" name="language" value="en" checked> English
<input type="radio" name="language" value="fr"> French
</form>
<div class="center">
<h1>
<?php
$name = $_POST['first_name'];
$lang = $_POST['language'];
if ($name != '') {
if ($lang == 'en') {
echo 'Hello ';
}
if ($lang == 'fr') {
echo 'Bonjour ';
}
echo ucfirst($name) . '!';
}
?>
</h1>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment