Skip to content

Instantly share code, notes, and snippets.

@daspecster
Created March 11, 2015 00:16
Show Gist options
  • Save daspecster/e70a9b82cfdc304f047a to your computer and use it in GitHub Desktop.
Save daspecster/e70a9b82cfdc304f047a to your computer and use it in GitHub Desktop.
PHP Ziptastic multi-step form example page 2
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"x-referrer: " . $_SERVER['HTTP_REFERER'] . " \r\n"
)
);
$postal_code = strip_tags(htmlspecialchars($_POST['postalcode'], ENT_QUOTES));
$context = stream_context_create($opts);
$result = file_get_contents('https://zip.getziptastic.com/v2/US/' . $postal_code, false, $context);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$_SESSION['user_postal_code'] = $_POST['postalcode'];
}
?>
<html>
<body>
<form action="/third_next_page.php" method="get">
City: <input type="text" name="city" value="<?php echo $result['city']?>" />
State: <input type="text" name="state" value="<?php echo $result['state']?>" />
Country: <input type="text" name="country" value="<?php echo $result['country']?>" />
<input type="submit">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment