Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@recck
Created September 26, 2012 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recck/3787924 to your computer and use it in GitHub Desktop.
Save recck/3787924 to your computer and use it in GitHub Desktop.
Week 5 - Day 10 - Using POST
<?php
/**
* Using POST
**/
// see if any post request has been made
if(count($_POST) > 0){
print_r($_POST);
}
/** Start Checkbox Example **/
if(isset($_POST['submit'])){
if(isset($_POST['engine']) && is_array($_POST['engine'])){
echo 'You selected: <br />';
foreach($_POST['engine'] AS $engine){
echo htmlentities($engine) . '<br />';
}
}else {
echo 'Please select at least ONE search engine!<br />';
}
}
?>
<form method="post">
Choose Your Favorite Search Engine(s)<br />
<input type="checkbox" name="engine[]" value="Google" /> Google<br />
<input type="checkbox" name="engine[]" value="Yahoo" /> Yahoo<br />
<input type="checkbox" name="engine[]" value="Bing" /> Bing<br />
<input type="submit" name="submit" value="Submit" />
</form>
<!-- end checkbox example -->
<!-- last example -->
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['name'])){
switch(strtolower($_POST['name'])){
case 'marcus':
echo 'Hello Professor!';
break;
case 'bob':
echo 'Hello Mr. TA!';
break;
case 'amanda':
echo 'Hello Student!';
break;
default:
echo 'Invalid name supplied!';
}
}else {
echo 'Please supply a name!';
}
}
?>
<form method="post">
Name: <input type="text" name="name" />
<input type="submit" value="Submit" name="submit" />
</form>
<!-- end last example -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment