-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_contact.php
94 lines (77 loc) · 1.98 KB
/
add_contact.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
$api_key = "cs0KtIkAgY9tayoVqLhRNgX4K68bcVjD"; // see https://telerivet.com/dashboard/api
$project_id = "PJ1d0c187f4b652026";
require_once dirname(dirname(__FILE__)) . '/htdocs/telerivet.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$name = $_POST['name'];
$phone_number = $_POST['phone_number'];
$email = $_POST['email'];
$api = new Telerivet_API($api_key);
$project = $api->initProjectById($project_id);
try
{
$contact = $project->getOrCreateContact(array(
'name' => $name,
'phone_number' => $phone_number,
'vars' => array('email' => $email),
));
$group = $project->getOrCreateGroup("Subscribers");
$contact->addToGroup($group);
$status_html = "<div class='success'>Contact saved successfully.</div>";
}
catch (Telerivet_Exception $ex)
{
$status_html = "<div class='error'>".htmlentities($ex->getMessage())."</div>";
}
}
else
{
$name = $phone_number = $email = '';
$status_html = '';
}
?>
<html>
<head>
<style type='text/css'>
body.sample_form
{
font-family:Verdana, sans-serif;
padding:20px;
}
.sample_form label
{
display:block;
font-weight:bold;
}
.sample_form .field
{
padding:8px 0px;
}
.sample_form .input-text
{
padding:3px;
}
</style>
</head>
<body class='sample_form'>
<h2>Add or update a Telerivet contact</h2>
<form method='POST'>
<div class='field'>
<label>Name</label>
<input class='input-text' type='text' name='name' value='<?php echo htmlentities($name); ?>' />
</div>
<div class='field'>
<label>Phone Number</label>
<input class='input-text' type='text' name='phone_number' value='<?php echo htmlentities($phone_number); ?>' />
</div>
<div class='field'>
<label>Email Address</label>
<input class='input-text' type='text' name='email' value='<?php echo htmlentities($email); ?>' />
</div>
<input type='submit' value='Save' />
<br /><br />
<?php echo $status_html; ?>
</form>
</body>
</html>