4 files added
3 files modified
| | |
| | | DB_HOST=localhost |
| | | DB_NAME=product_db |
| | | DB_USER=product_db_user |
| | | DB_PASSWORD=secret |
| | | DB_NAME=contact_db |
| | | DB_USER=root |
| | | DB_PASSWORD= |
| | | SHOW_ERRORS=1 |
| | |
| | | <?php |
| | | namespace App\Controllers; |
| | | |
| | | use App\Models\FiatModel; |
| | | use Framework\Controller; |
| | | class Fiat extends Controller { |
| | | |
| | | public function __construct() |
| | | public function __construct(private FiatModel $model) |
| | | { |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | public function contact() { |
| | | if($_SERVER['REQUEST_METHOD'] === 'POST') { |
| | | $data = [ |
| | | "email" => $this->request->post["email"], |
| | | "number" => $this->request->post["number"] |
| | | ]; |
| | | |
| | | $this->model->insert($data); |
| | | } |
| | | |
| | | |
| | | return $this->view("Fiat/contact.mvc.php", [ |
| | | ]); |
| | | } |
New file |
| | |
| | | <?php |
| | | namespace App\Models; |
| | | |
| | | use PDO; |
| | | use Framework\Model; |
| | | class FiatModel extends Model { |
| | | //protected ?string $table = "product"; |
| | | |
| | | |
| | | protected function validate(array $data): void { |
| | | |
| | | if(empty($data["email"])) { |
| | | $this->addError("email","email is required"); |
| | | } |
| | | if(empty($data["number"])) { |
| | | $this->addError("number","cell number is required"); |
| | | } |
| | | |
| | | var_dump($this->getErrors()); |
| | | } |
| | | } |
| | |
| | | {% include "../views/Fiat/header.mvc.php" %} |
| | | |
| | | <main> |
| | | <form action="contact.php" method="post"> |
| | | <form action="/fiat/contact" method="post"> |
| | | Inserisci l'email: |
| | | <input type="email" name="email" placeholder="inserisci l'email"> <br> |
| | | Inserisci il numero: |