Last active
August 29, 2015 14:17
-
-
Save amandabee/c28c24acda0f8c2da528 to your computer and use it in GitHub Desktop.
PHP Form Action Demo (See it in action at http://freegreentea.info/form/)
This file contains 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 | |
if(isset($_POST['submit'])) { | |
echo "<pre>"; | |
// Everything that was entered into the form lives in an associative array called $_POST | |
// Guess what the array is called if you used GET as your form action? | |
print_r($_POST); | |
// You can create a new variable by stringing together strings and variables. | |
$new_url = "http://" . $_POST['something_unique'] . "/more_strings"; | |
print($new_url); | |
// You can also continue to append things to that URL, with ".=" | |
if(isset($_POST['the_pulldown'])) { | |
$new_url .= "&pulldown=" . $_POST['the_pulldown']; | |
print("<br />New new URL: " . $new_url); | |
} | |
// So with a few "if" statements, you can build up a URL that starts with the things you know you need: | |
$api_call = "https://www.documentcloud.org/api/search.json?q=group:dhpraxis"; | |
// and adds the search criteria your user submitted. | |
//Once you know your URL, you can use cURL or guzzler to pull the JSON that DocumentCloud provides | |
//You'll pull the JSON into an associative array and use that to populate a page of content. | |
echo "</pre>"; | |
} else { | |
phpinfo(); | |
//If the user didn't come here by form submit, you want to show ... something else! | |
// either the search form or a link back to the search form. | |
} | |
?> |
This file contains 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
<form action="action.php" method="POST" name="sample"> | |
<input type="text" name="something_unique" value="say anything"> | |
<select id="the_pulldown" name="the_pulldown" class="input-large"> | |
<option>Pick this</option> | |
<option>Or that</option> | |
</select> | |
<input type="submit" value="push me" name="submit"> | |
</form> |
This file contains 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 lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Simple Form Demo</title> | |
<!-- Bootstrap --><!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> | |
<!-- Optional theme --> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"> | |
<style type="text/css"> | |
body { | |
background: #EEE; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<?php include 'form.html'; ?> | |
</div><!-- /container --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment