minor updates

This commit is contained in:
essae 2025-05-13 01:20:16 -04:00
parent 761c41d3bb
commit b48a5f8e0c
2 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<?php
/**
* File: ContactController.php
* Version: 1.2
* Version: 1.5
* Path: /app/Controllers/ContactController.php
* Purpose: Handles contact form display and submission logic.
* Project: Wizdom Networks Website
@ -14,6 +14,7 @@ use WizdomNetworks\WizeWeb\Utilities\Logger;
use WizdomNetworks\WizeWeb\Utilities\Validator;
use WizdomNetworks\WizeWeb\Utilities\Response;
use WizdomNetworks\WizeWeb\Utilities\Sanitizer;
use WizdomNetworks\WizeWeb\Utilities\Database;
use WizdomNetworks\WizeWeb\Models\ContactModel;
use Exception;
@ -58,15 +59,18 @@ class ContactController
$message = Sanitizer::sanitizeString($data['message']);
// Validate email format
if (!Validator::isEmail($email)) {
if (!Validator::IsEmail($email)) {
Response::badRequest('Invalid email address.');
}
$ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? 'unknown';
// Insert into database
$contact = new ContactModel();
// Create DB connection and save to DB
$database = new Database();
$pdo = $database->getConnection();
$contact = new ContactModel($pdo);
$result = $contact->save([
'first_name' => $firstName,
'last_name' => $lastName,
@ -77,7 +81,7 @@ class ContactController
]);
if (!$result) {
Logger::logError("Failed to save contact form submission for email: $email");
Logger::error("Failed to save contact form submission for email: $email");
Response::serverError('An error occurred while submitting your message. Please try again later.');
}
@ -86,7 +90,7 @@ class ContactController
'message' => 'Your message has been successfully submitted. Thank you!'
]);
} catch (Exception $e) {
Logger::logError("Exception during contact form submission: " . $e->getMessage());
Logger::error("Exception during contact form submission: " . $e->getMessage());
Response::serverError('A server error occurred. Please try again later.');
}
}

View File

@ -37,7 +37,7 @@ class Database
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', $_ENV['DB_HOST'], $_ENV['DB_NAME']);
try {
$this->connection = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
$this->connection = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASS']);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Logger::info('Database connection established successfully.');
} catch (PDOException $e) {