| | |
| | | $smarty->setTemplateDir('../ihtml'); |
| | | $smarty->setCompileDir('../compile'); |
| | | |
| | | $error = []; |
| | | $number = $_GET['number'] ?? ''; |
| | | $email = $_GET['email'] ?? ''; |
| | | $errorMsgs = []; |
| | | $validazioneOk = true; |
| | | |
| | | $number = $_POST['number'] ?? ''; |
| | | $email = $_POST['email'] ?? ''; |
| | | $msg = ''; |
| | | |
| | | |
| | | function insertDataOnTable(mysqli $mysql, string $email, string $number) { |
| | | $esitoInserimento = false; |
| | | $query = "INSERT INTO Contact VALUES (NULL, '$email', '$number');"; |
| | | try { |
| | | $mysql->query($query); |
| | | $esitoInserimento = true; |
| | | } catch (Exception $e) { |
| | | echo $e->getMessage(); |
| | | } |
| | | return $esitoInserimento; |
| | | } |
| | | |
| | | function controlloErrori(string $email, string $number, array &$errorMsgs) { |
| | | if(!is_numeric($number) || strlen($number) != 10) { |
| | | $errorMsgs['number'] = 'Numero di telefono non corretto'; |
| | | }else { |
| | | //$errorMsgs['number'] = ''; |
| | | } |
| | | |
| | | if(!is_numeric($number) || strlen($number) != 10) { |
| | | $error['number'] = 'Numero di telefono non corretto'; |
| | | }else { |
| | | $error['number'] = ''; |
| | | } |
| | | if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
| | | $errorMsgs['email'] = 'Email non valida'; |
| | | } else { |
| | | //$errorMsgs['email'] = ''; |
| | | } |
| | | |
| | | if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
| | | $error['email'] = 'Email non valida'; |
| | | } else { |
| | | $error['email'] = ''; |
| | | $validazioneOk = count($errorMsgs) == 0; |
| | | |
| | | return $validazioneOk; |
| | | } |
| | | |
| | | |
| | | |
| | | if($_SERVER['REQUEST_METHOD'] === 'POST') { |
| | | $validazioneOk = controlloErrori($email, $number, $errorMsgs); |
| | | |
| | | if($validazioneOk) { |
| | | try { |
| | | $conn = new mysqli('127.0.0.1', 'root', '', 'contact_db'); |
| | | } catch (Exception $e) { |
| | | die($e->getMessage()); |
| | | } |
| | | |
| | | $esitoInserimento = insertDataOnTable($conn, $email, $number); |
| | | |
| | | if($esitoInserimento == true) { |
| | | $smarty->display('conferma.tpl'); |
| | | exit; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | $smarty->assign('cellNumber', $number); |
| | | $smarty->assign('email', $email); |
| | | |
| | | $smarty->assign('error', $error); |
| | | $smarty->assign('formMsg', $msg); |
| | | |
| | | $smarty->assign('errorMsgs', $errorMsgs); |
| | | |
| | | $smarty->display('contact.tpl'); |
| | | |
| | | |
| | | ?> |