-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_handler.php
More file actions
45 lines (37 loc) · 1.08 KB
/
form_handler.php
File metadata and controls
45 lines (37 loc) · 1.08 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
<?php
function look()
{
function getParameter(string $name): ?string
{
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, true);
return $input[$name] ?? null;
}
$name = getParameter('name');
$email = getParameter('email');
$profession = getParameter('profession');
$checkbox = getParameter('agreement');
$fp = @fopen("./data/$email.txt", 'w+');
// выводить 500 и message через json
if ($fp === false)
{
echo json_encode(['message' => 'файл не открылся', "status" => 500]);
return;
}
fwrite($fp, 'Email: ');
fwrite($fp, $email);
fwrite($fp, "\n");
fwrite($fp, 'Имя: ');
fwrite($fp, $name);
fwrite($fp, "\n");
fwrite($fp, 'Деятельность: ');
fwrite($fp, $profession);
fwrite($fp, "\n");
fwrite($fp, 'Согласие: ');
fwrite($fp, $checkbox);
fwrite($fp, "\n");
fclose($fp);
// если php отработал без ошибок, то вывод статуса 200
echo json_encode(["status" => 200]);
}
look();