Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:17
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 amandabee/c28c24acda0f8c2da528 to your computer and use it in GitHub Desktop.
Save amandabee/c28c24acda0f8c2da528 to your computer and use it in GitHub Desktop.
PHP Form Action Demo (See it in action at
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?
// You can create a new variable by stringing together strings and variables.
$new_url = "http://" . $_POST['something_unique'] . "/more_strings";
// 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 = "";
// 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 {
//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.
<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>
<input type="submit" value="push me" name="submit">
<!DOCTYPE html>
<html lang="en">
<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="//">
<!-- Optional theme -->
<link rel="stylesheet" href="//">
<style type="text/css">
body {
background: #EEE;
<div class="container">
<?php include 'form.html'; ?>
</div><!-- /container -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment