Skip to content

Instantly share code, notes, and snippets.

/onboarding.php

Created Jun 22, 2015
Embed
What would you like to do?
<html>
<head>
<meta charset="UTF-8">
<title>Our service rocks! Text us to find out!</title>
</head>
<script>
function getPhoneNumber() {
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", 'https://www.sendsonar.com/api/v1/phone_numbers/available', true );
xmlHttp.setRequestHeader("X-Publishable-Key","**YOUR PUBLISHABLE KEY HERE**");
xmlHttp.setRequestHeader("Content-type","application/json");
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState==4 && xmlHttp.status==200) {
phone_no = JSON.parse(xmlHttp.responseText);
pretty_phone = phone_no.available_number.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
// Might want to format the returning 10 digit number
document.getElementById('phone').innerHTML = pretty_phone;
}
}
xmlHttp.send();
}
</script>
<body onload="getPhoneNumber()" style="margin:0px;">
<div style="top: 0px; left: 0px; position: fixed; height: 55px; width: 99%; background-color: orange; color: white; padding: 5px; text-align:center; font-family: helvetica;">
<?php
// If the form was submitted, then check the parameters first
list($first_name, $last_name, $phone_number) = array($_POST['first_name'],$_POST['last_name'],$_POST['phone_number']);
if ($_POST["form_submitted"]) {
if (!$phone_number || !$last_name || !$phone_number) {
?><h3>Please provide your first name, last name, and phone number</h3><?php
} else {
?><h3>Thanks, Bro! Please check your phone. You'll receive a text soon!</h3><?php
}
} else {
?><h3>BroPizza. When hunger strikes you bro, we strike back!</h3><?php
}
?>
</div>
<div style="height: 50vh; background-color: black; color: white; text-align:center; font-family: helvetica;">
<h3 style="padding-top:105px;">Sign up here</h3>
<form name="Contact Info" method="POST">
<input type="text" name="first_name" placeholder="First Name" value="<?=$first_name?>" style="text-align: center;"/>
<input type="text" name="last_name" placeholder="Last Name" value="<?=$last_name?>" style="text-align: center;"/>
<input type="phone" name="phone_number" placeholder="(123) 456-7890" value="<?=$phone_number?>" style="text-align: c
enter;"/>
<input type="submit" name="form_submitted" value="Text Me, Bro!"/>
</form>
</div>
<div style="height: 50vh; padding: 5px; text-align: center; font-family:helvetica;">
<h3>Or send us an SMS at</h3>
<!-- Probably a good idea to have a default number incase the call fails -->
<span id="phone">XXX-YYY-ZZZZ</span>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment