1 files deleted
1 files added
2 files modified
| | |
| | | <?php |
| | | namespace App\Controllers; |
| | | |
| | | use App\Models\FiatModel; |
| | | use App\Models\Contact; |
| | | use Framework\Controller; |
| | | class Fiat extends Controller { |
| | | |
| | | public function __construct(private FiatModel $model) |
| | | public function __construct(private Contact $model) |
| | | { |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | public function contact() { |
| | | |
| | | if($_SERVER['REQUEST_METHOD'] === 'POST') { |
| | | $data = [ |
| | | "email" => $this->request->post["email"], |
| | | "number" => $this->request->post["number"] |
| | | "telefono" => $this->request->post["telefono"] |
| | | ]; |
| | | |
| | | |
| | | $this->model->insert($data); |
| | | } |
| | | |
| | | $errors = $this->model->getErrors(); |
| | | |
| | | return $this->view("Fiat/contact.mvc.php", [ |
| | | "errors" => $errors |
| | | ]); |
| | | } |
| | | |
New file |
| | |
| | | <?php |
| | | namespace App\Models; |
| | | |
| | | use PDO; |
| | | use Framework\Model; |
| | | class Contact extends Model { |
| | | //protected ?string $table = "product"; |
| | | |
| | | public function controlloSpamEmail(string $email, ): bool { |
| | | $spam = false; |
| | | $query = "SELECT email, dtm_richiesta FROM Contact WHERE email = '$email' AND dtm_richiesta BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW();"; |
| | | $connection = $this->database->getConnection(); |
| | | |
| | | $result = $connection->query($query); |
| | | |
| | | $rowcount = count($result->fetchAll(PDO::FETCH_ASSOC)); |
| | | |
| | | |
| | | if ($rowcount > 0) { |
| | | $spam = true; |
| | | } |
| | | |
| | | return $spam; |
| | | } |
| | | protected function validate(array $data): void { |
| | | |
| | | if(empty($data["email"])) { |
| | | $this->addError("email","email is required"); |
| | | } |
| | | if(empty($data["telefono"])) { |
| | | $this->addError("telefono","cell number is required"); |
| | | } |
| | | if($this->controlloSpamEmail($data["email"])) { |
| | | $this->addError("spam", "non puoi mandare la stessa mail, aspetta un pò di tempo"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | Inserisci l'email: |
| | | <input type="email" name="email" placeholder="inserisci l'email"> <br> |
| | | Inserisci il numero: |
| | | <input type="text" name="number" placeholder="inserisci il numero"> <br> |
| | | <input type="text" name="telefono" placeholder="inserisci il numero"> <br> |
| | | <button type="submit">clicca qui</button> |
| | | </form> |
| | | {$formMsg} |
| | | {foreach from=$error item=errore key=campo} |
| | | {$errore} |
| | | <br> |
| | | {/foreach} |
| | | {% foreach ($errors as $error): %} |
| | | <h4>{{error}}</h4> |
| | | {% endforeach; %} |
| | | </main> |
| | | |
| | | {% include "../views/Fiat/footer.mvc.php" %} |