progetto di prova che mostra le macchine fiat e un form che permette di contattare
filippo.bertilotti
2024-04-29 493a489d06908f41fe86cefbb8a4d7959886fc3e
cambio metodo da GET a POST, aggiunto controllo array per inserimento dati
2 files modified
26 ■■■■ changed files
htdocs/contact.php 24 ●●●● patch | view | raw | blame | history
ihtml/contact.tpl 2 ●●● patch | view | raw | blame | history
htdocs/contact.php
@@ -7,8 +7,8 @@
    $smarty->setCompileDir('../compile');
    $error = [];
    $number = $_GET['number'] ?? '';
    $email = $_GET['email'] ?? '';
    $number = $_POST['number'] ?? '';
    $email = $_POST['email'] ?? '';
@@ -24,25 +24,27 @@
    if(!is_numeric($number) || strlen($number) != 10) {
        $error['number'] = 'Numero di telefono non corretto';
    }else {
        $error['number'] = '';
        //$error['number'] = '';
    }
    if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $error['email'] = 'Email non valida';
    } else {
        $error['email'] = '';
        //$error['email'] = '';
    }
    
    if(count($error) == 0) {
        try {
            $conn = new mysqli('127.0.0.1', 'root', '', 'contact_db');
        } catch (Exception $e) {
            die($e->getMessage());
        }
    try {
        $conn = new mysqli('127.0.0.1', 'root', '', 'contact_db');
    } catch (Exception $e) {
        die($e->getMessage());
        insertDataOnTable($conn, $email, $number);
    }
    insertDataOnTable($conn, $email, $number);
    
    
ihtml/contact.tpl
@@ -10,7 +10,7 @@
    {include file="header.tpl"}
    <main>
        {* FORM *}
        <form action="contact.php">
        <form action="contact.php" method="post">
            Inserisci l'email:
            <input type="email" name="email" placeholder="inserisci l'email"> <br>
            Inserisci il numero: