commit | author | age
|
395ba3
|
1 |
<?php |
F |
2 |
require '../vendor/autoload.php'; |
|
3 |
use Smarty\Smarty; |
|
4 |
$smarty = new Smarty(); |
|
5 |
|
|
6 |
$smarty->setTemplateDir('../ihtml'); |
|
7 |
$smarty->setCompileDir('../compile'); |
25190e
|
8 |
|
f926d7
|
9 |
$errorMsgs = []; |
4b29be
|
10 |
$errorCheck = true; |
f926d7
|
11 |
|
493a48
|
12 |
$number = $_POST['number'] ?? ''; |
F |
13 |
$email = $_POST['email'] ?? ''; |
f926d7
|
14 |
$msg = ''; |
25190e
|
15 |
|
09c7af
|
16 |
|
f926d7
|
17 |
function insertDataOnTable(mysqli $mysql, string $email, string $number) { |
F |
18 |
$query = "INSERT INTO Contact VALUES (NULL, '$email', '$number');"; |
6d88a8
|
19 |
try { |
09c7af
|
20 |
$mysql->query($query); |
6d88a8
|
21 |
} catch (Exception $e) { |
09c7af
|
22 |
echo $e->getMessage(); |
24112e
|
23 |
} |
F |
24 |
} |
|
25 |
|
f926d7
|
26 |
function controlloErrori(string $email, string $number, array &$errorMsgs) { |
b174d4
|
27 |
if(!is_numeric($number) || strlen($number) != 10) { |
f926d7
|
28 |
$errorMsgs['number'] = 'Numero di telefono non corretto'; |
F |
29 |
$errorCheck = true; |
|
30 |
|
b174d4
|
31 |
}else { |
f926d7
|
32 |
//$errorMsgs['number'] = ''; |
F |
33 |
$errorCheck = false; |
b174d4
|
34 |
} |
F |
35 |
|
|
36 |
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
f926d7
|
37 |
$errorMsgs['email'] = 'Email non valida'; |
F |
38 |
$errorCheck = true; |
b174d4
|
39 |
} else { |
f926d7
|
40 |
//$errorMsgs['email'] = ''; |
F |
41 |
$errorCheck = false; |
b174d4
|
42 |
} |
f926d7
|
43 |
|
F |
44 |
return $errorCheck; |
366466
|
45 |
} |
6d88a8
|
46 |
|
09c7af
|
47 |
|
b174d4
|
48 |
|
F |
49 |
if($_SERVER['REQUEST_METHOD'] === 'POST') { |
f926d7
|
50 |
$errorCheck = controlloErrori($email, $number, $errorMsgs); |
b174d4
|
51 |
|
f926d7
|
52 |
if(count($errorMsgs) == 0) { |
b174d4
|
53 |
try { |
F |
54 |
$conn = new mysqli('127.0.0.1', 'root', '', 'contact_db'); |
|
55 |
} catch (Exception $e) { |
|
56 |
die($e->getMessage()); |
|
57 |
} |
|
58 |
|
|
59 |
insertDataOnTable($conn, $email, $number); |
493a48
|
60 |
} |
09c7af
|
61 |
} |
6d88a8
|
62 |
|
F |
63 |
|
24112e
|
64 |
|
c34154
|
65 |
$smarty->assign('cellNumber', $number); |
F |
66 |
$smarty->assign('email', $email); |
f926d7
|
67 |
$smarty->assign('formMsg', $msg); |
4b29be
|
68 |
|
f926d7
|
69 |
$smarty->assign('errorMsgs', $errorMsgs); |
366466
|
70 |
|
4b29be
|
71 |
if($errorCheck == false) { |
F |
72 |
$smarty->display('conferma.tpl'); |
|
73 |
}else { |
|
74 |
$smarty->display('contact.tpl'); |
|
75 |
} |
|
76 |
|
395ba3
|
77 |
?> |