Simple PHP script to invite slack users
April 29, 2015 ยท View on GitHub
Join on Slack!
<?php
$showform = false;
$error = false;
if (isset($_POST['first'])){
if (strlen($_POST['first']) > 1 && strlen($_POST['last']) > 1 && strlen($_POST['mail']) > 5){
sendForm();
} else {
$showform = true;
$error = true;
}
} else {
$showform = true;
}
if ($showform){
if ($error){
?>
<p style="font-family: 'Roboto', sans-serif; color: #9d3d3d">
Please fill in all fields
</p>
<?php
}
showForm();
}
?>
</div>
</body>
urlencode($email),
'first_name' => urlencode($first),
'token' => TOKEN,
'set_active' => urlencode('true'),
'_attempts' => '1'
);
// url-ify the data for the POST
$fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
// open connection
$ch = curl_init();
// set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $slackInviteUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
// exec
$replyRaw = curl_exec($ch);
$reply=json_decode($replyRaw,true);
if($reply['ok']==false) {
echo ''; echo 'Something went wrong, try again!'; echo '
'; showForm(); } else { echo ''; echo 'Invited successfully. Check your email. It should arrive within a couple minutes'; echo '
'; } // close connection curl_close($ch); } function showForm(){ ?> <form method="post">
<p style="font-family: 'Roboto', sans-serif; color: #ffffff">
First Name
</p>
<input type="text" name="first" style="width: 250px; " <?php echo strlen($_POST['first']) > 0 ? 'value="'.$_POST['first'].'"' : ''; ?> />
<p style="font-family: 'Roboto', sans-serif; color: #ffffff">
Last Name
</p>
<input type="text" name="last" style="width: 250px; " <?php echo strlen($_POST['last']) > 0 ? 'value="'.$_POST['last'].'"' : ''; ?> />
<p style="font-family: 'Roboto', sans-serif; color: #ffffff">
Email address
</p>
<input type="text" name="mail" style="width: 250px; " <?php echo strlen($_POST['mail']) > 0 ? 'value="'.$_POST['mail'].'"' : ''; ?> />
<p>
<input type="submit" value="Sign me up!" />
</p>
</form>
<?php
}