Created
September 26, 2012 13:07
-
-
Save recck/3787924 to your computer and use it in GitHub Desktop.
Week 5 - Day 10 - Using POST
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
<?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