112 lines
5.1 KiB
PHP
112 lines
5.1 KiB
PHP
<?php
|
||
require_once __DIR__ . '/../includes/db.php';
|
||
|
||
$success = false;
|
||
$errors = [];
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
// Store raw values; htmlspecialchars is applied only at output time
|
||
$name = trim($_POST['name'] ?? '');
|
||
$email = trim($_POST['email'] ?? '');
|
||
$phone = trim($_POST['phone'] ?? '');
|
||
$subject = trim($_POST['subject'] ?? '');
|
||
$message = trim($_POST['message'] ?? '');
|
||
|
||
if (!$name) $errors[] = 'Name is required.';
|
||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'A valid email is required.';
|
||
if (!$message) $errors[] = 'Message is required.';
|
||
|
||
if (empty($errors)) {
|
||
try {
|
||
$db = get_db();
|
||
$stmt = $db->prepare(
|
||
"INSERT INTO contacts (name, email, phone, subject, message)
|
||
VALUES (?, ?, ?, ?, ?)"
|
||
);
|
||
$stmt->execute([$name, $email, $phone, $subject, $message]);
|
||
$success = true;
|
||
} catch (PDOException $e) {
|
||
$errors[] = 'Sorry, we could not save your message right now. Please try again.';
|
||
}
|
||
}
|
||
}
|
||
?>
|
||
|
||
<section class="section page-hero">
|
||
<div class="container">
|
||
<span class="section__eyebrow">Reach Out</span>
|
||
<h1 class="section__heading">Contact Us</h1>
|
||
<p class="section__sub">Questions about service, coverage, or your account? We're here to help.</p>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="section">
|
||
<div class="container contact__grid">
|
||
|
||
<div class="contact__info">
|
||
<h2 class="contact__heading">Get In Touch</h2>
|
||
<ul class="contact__details">
|
||
<li>📞 <a href="tel:+10000000000">(000) 000-0000</a></li>
|
||
<li>✉ <a href="mailto:info@alwisp.com">info@alwisp.com</a></li>
|
||
<li>🕐 Mon–Fri 8am–6pm CST<br>Emergency support 24/7</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="contact__form-wrap">
|
||
<?php if ($success): ?>
|
||
<div class="alert alert--success" role="alert">
|
||
Thanks! We'll be in touch within one business day.
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (!empty($errors)): ?>
|
||
<div class="alert alert--error" role="alert">
|
||
<ul><?php foreach ($errors as $e) echo "<li>" . $e . "</li>"; ?></ul>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<form method="post" action="/contact" class="form" novalidate>
|
||
<div class="form__row form__row--2">
|
||
<div class="form__group">
|
||
<label for="name" class="form__label">Name <span aria-hidden="true">*</span></label>
|
||
<input type="text" id="name" name="name" class="form__input" required
|
||
value="<?= htmlspecialchars($_POST['name'] ?? '') ?>">
|
||
</div>
|
||
<div class="form__group">
|
||
<label for="email" class="form__label">Email <span aria-hidden="true">*</span></label>
|
||
<input type="email" id="email" name="email" class="form__input" required
|
||
value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
|
||
</div>
|
||
</div>
|
||
<div class="form__row form__row--2">
|
||
<div class="form__group">
|
||
<label for="phone" class="form__label">Phone</label>
|
||
<input type="tel" id="phone" name="phone" class="form__input"
|
||
value="<?= htmlspecialchars($_POST['phone'] ?? '') ?>">
|
||
</div>
|
||
<div class="form__group">
|
||
<label for="subject" class="form__label">Subject</label>
|
||
<select id="subject" name="subject" class="form__input">
|
||
<option value="">Select a topic…</option>
|
||
<option value="new-project">New Project Inquiry</option>
|
||
<option value="mesh-networking">Mesh Networking</option>
|
||
<option value="managed-services">Managed Services</option>
|
||
<option value="structured-cabling">Structured Cabling</option>
|
||
<option value="access-control">Access Control</option>
|
||
<option value="ip-cameras">IP Camera Systems</option>
|
||
<option value="support">Technical Support</option>
|
||
<option value="other">Other</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form__group">
|
||
<label for="message" class="form__label">Message <span aria-hidden="true">*</span></label>
|
||
<textarea id="message" name="message" class="form__input form__textarea" rows="5" required><?= htmlspecialchars($_POST['message'] ?? '') ?></textarea>
|
||
</div>
|
||
<button type="submit" class="btn btn--primary">Send Message</button>
|
||
</form>
|
||
</div>
|
||
|
||
</div>
|
||
</section>
|