ContactController.php 906 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Controllers;
  3. use App\Core\Application;
  4. use App\Core\Controller;
  5. use App\Core\Form\Form;
  6. use App\Core\Request;
  7. use App\Core\Response;
  8. use App\Models\ContactModel;
  9. class ContactController extends Controller
  10. {
  11. /*
  12. * Renderiza la página de contacto
  13. * y envía un email de contacto.
  14. */
  15. public function create(Request $request, Response $response)
  16. {
  17. $contactModel = new ContactModel();
  18. $contactModel->loadData($request->getBody());
  19. if (! $request->isPost() || ! $contactModel->validate() || ! $contactModel->send()) {
  20. $form = new Form();
  21. return $this->render('contact', [
  22. 'form' => $form,
  23. 'model' => $contactModel,
  24. ]);
  25. }
  26. Application::$app->session->setFlash('success', 'Gracias por contactarnos.');
  27. $response->redirect('/contacto');
  28. }
  29. }