-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontribute.php
More file actions
110 lines (95 loc) · 3.44 KB
/
contribute.php
File metadata and controls
110 lines (95 loc) · 3.44 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/handler.php';
require_once __DIR__ . '/signup.php';
/**
* Contribute page controller
*/
class Contribute extends Signup {
private $_required = ['name', 'username', 'email', 'help'];
public function prepare(){
$this->ensureSettingOr500('slack_board_webhook');
}
public function get(){
$content = $this->load('contribute.html');
return $this->page($content);
}
public function post(){
if(!$this->isAjax()){
$this->redirect('/contribute');
}
$errors = [];
$slack = [];
$message = 'Thank you for helping make DATCODE the best place for Black technolists! We will get back to you shortly.';
foreach($this->_required as $field){
$pass = false;
if(isset($_POST[$field])){
if($field == 'help') {
$pass = count($_POST[$field]) > 0;
$val = $_POST[$field];
}else{
$val = strip_tags(trim($_POST[$field]));
$pass = $val != '';
if($field == 'notes' && $pass){
$pass = strlen($val) < 500;
}
}
}
if(!$pass){
$errors[] = $field;
}else{
$slack[$field] = $val;
}
}
if(!count($errors)){
$headers = [
'Content-type' => 'application/json',
];
$post = [
'text' => 'A Member Wants To Contribute',
'attachments' => [
[
'pretext' => '',
'fields' => [
[
'title' => 'Name',
'value' => $slack['name'],
'short' => false
],
[
'title' => 'Username',
'value' => $slack['username'],
'short' => false
],
[
'title' => 'Email Address',
'value' => $slack['email'],
'short' => false
],
[
'title' => 'How they\'d like to help',
'value' => implode(", ", $slack['help']),
'short' => false
],
[
'title' => 'Notes',
'value' => isset($_POST['notes']) ? $_POST['notes'] : 'none',
'short' => false
],
]
]
]
];
$url = sprintf('https://hooks.slack.com/services/%s', $this->getConfig('slack_board_webhook'));
$post = json_encode($post);
$this->callAPI('POST', $url, $post, $headers);
}else{
$message = 'Please correct the form errors to continue your submission.';
}
$resp = [
'errors' => $errors,
'message' => $message,
];
return $this->json($resp);
}
}