-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
124 lines (100 loc) · 4.36 KB
/
contact.php
File metadata and controls
124 lines (100 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
// ── Form Handling ─────────────────────────────────────────────
$form_success = false;
$form_errors = [];
$old = ['name' => '', 'email' => '', 'message' => ''];
$show_captcha = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim(htmlspecialchars($_POST['sender_name'] ?? '', ENT_QUOTES, 'UTF-8'));
$email = trim(htmlspecialchars($_POST['sender_email'] ?? '', ENT_QUOTES, 'UTF-8'));
$message = trim(htmlspecialchars($_POST['sender_message'] ?? '', ENT_QUOTES, 'UTF-8'));
$captcha = isset($_POST['captcha_confirm']);
$old = ['name' => $name, 'email' => $email, 'message' => $message];
if ($name === '') $form_errors[] = 'Name is required.';
if ($email === '') $form_errors[] = 'Email address is required.';
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) $form_errors[] = 'Please enter a valid email address.';
if ($message === '') $form_errors[] = 'Message cannot be empty.';
if (empty($form_errors) && !$captcha) {
$show_captcha = true;
}
if (empty($form_errors) && $captcha) {
$form_success = true;
// ── TODO: Send email or save to DB here ───────────────
// mail('you@example.com', 'New message from ' . $name, $message, 'From: ' . $email);
$old = ['name' => '', 'email' => '', 'message' => ''];
$show_captcha = false;
}
}
$current_page = 'contact';
$page_title = 'Contact';
require 'header.php';
?>
<!-- PAGE 3 · Contact -->
<div class="hero">
<span class="tag">✉ Let's connect</span>
<h1>Get in</h1>
<h1 class="accent-line">Touch</h1>
<div class="divider"></div>
<p class="subtitle">Have a question or want to work together? Send me a message.</p>
<div class="form-wrap">
<?php if ($form_success): ?>
<div class="success-msg">
✅ Message sent! I'll get back to you soon.
</div>
<?php else: ?>
<?php if (!empty($form_errors)): ?>
<ul class="error-list">
<?php foreach ($form_errors as $err): ?>
<li><?php echo htmlspecialchars($err); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<form method="POST" action="contact.php">
<div class="form-group">
<label for="sender_name">Your Name</label>
<input
type="text"
id="sender_name"
name="sender_name"
placeholder="Juan dela Cruz"
value="<?php echo val($old['name']); ?>"
<?php echo in_array('Name is required.', $form_errors) ? 'class="error"' : ''; ?>
/>
</div>
<div class="form-group">
<label for="sender_email">Email Address</label>
<input
type="email"
id="sender_email"
name="sender_email"
placeholder="juan@example.com"
value="<?php echo val($old['email']); ?>"
<?php echo (in_array('Email address is required.', $form_errors) || in_array('Please enter a valid email address.', $form_errors)) ? 'class="error"' : ''; ?>
/>
</div>
<div class="form-group">
<label for="sender_message">Your Message</label>
<textarea
id="sender_message"
name="sender_message"
placeholder="Write your message here…"
<?php echo in_array('Message cannot be empty.', $form_errors) ? 'class="error"' : ''; ?>
><?php echo val($old['message']); ?></textarea>
</div>
<?php if ($show_captcha): ?>
<div class="captcha-box">
<input type="checkbox" class="captcha-check" id="captcha_confirm" name="captcha_confirm" />
<label class="captcha-label" for="captcha_confirm">I'm not a robot</label>
<div class="captcha-logo">reCAPTCHA<br><span style="font-size:0.6rem">Privacy · Terms</span></div>
</div>
<?php endif; ?>
<div class="submit-row">
<button type="submit" class="btn-submit">
<?php echo $show_captcha ? 'Confirm & Send' : 'Send Message'; ?>
</button>
</div>
</form>
<?php endif; ?>
</div>
</div>
<?php require 'footer.php'; ?>