Skip to content

Commit 9f19c23

Browse files
author
olaru
committed
contact form backend
1 parent 774eb82 commit 9f19c23

19 files changed

Lines changed: 880 additions & 138 deletions

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"doctrine/doctrine-fixtures-bundle": "^4.3",
3434
"dotkernel/dot-cache": "^4.0",
3535
"dotkernel/dot-errorhandler": "^5.0.0",
36+
"dotkernel/dot-mail": "^5.4",
3637
"dotkernel/dot-response-header": "^3.6",
3738
"laminas/laminas-component-installer": "^3.5.0",
3839
"laminas/laminas-config-aggregator": "^1.17.0",

‎config/autoload/mail.global.php‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$contactEmail = 'example@mail.com';
6+
7+
return [
8+
'dot_mail' => [
9+
'contact' => [
10+
'message_options' => [
11+
'from' => $contactEmail,
12+
'from_name' => 'Dotkernel',
13+
'to' => [$contactEmail],
14+
'subject' => 'New contact form submission',
15+
'body' => [
16+
'content' => '',
17+
'charset' => 'utf-8',
18+
],
19+
'attachments' => [
20+
'files' => [],
21+
'dir' => [
22+
'iterate' => false,
23+
'path' => 'data/mail/attachments',
24+
'recursive' => false,
25+
],
26+
],
27+
],
28+
'transport' => 'sendmail',
29+
],
30+
'log' => [
31+
'sent' => getcwd() . '/log/mail-sent.log',
32+
],
33+
],
34+
'twig' => [
35+
'globals' => [
36+
'contact_email' => $contactEmail,
37+
],
38+
],
39+
];

‎config/config.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// Dotkernel packages
2828
\Dot\ErrorHandler\ConfigProvider::class,
2929
\Dot\Log\ConfigProvider::class,
30+
\Dot\Mail\ConfigProvider::class,
3031
\Dot\Cache\ConfigProvider::class,
3132
\Dot\ResponseHeader\ConfigProvider::class,
3233

‎public/css/contact.css‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/js/app.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Contact page: topic pills and the client-side "message sent" state.
2-
// The form is not wired to a backend yet, so submit only swaps the panels.
31
(function () {
42
var form = document.querySelector('[data-contact-form]');
53
if (!form) {
@@ -8,41 +6,14 @@
86

97
var topicInput = form.querySelector('[data-contact-topic]');
108
var pills = form.querySelectorAll('[data-topic]');
11-
var sent = document.querySelector('[data-contact-sent]');
12-
var sentTopic = sent.querySelector('[data-contact-sent-topic]');
13-
var reset = sent.querySelector('[data-contact-reset]');
14-
15-
function currentPill() {
16-
return form.querySelector('[data-topic][aria-pressed="true"]');
17-
}
18-
19-
function selectTopic(id) {
20-
pills.forEach(function (pill) {
21-
pill.setAttribute('aria-pressed', String(pill.getAttribute('data-topic') === id));
22-
});
23-
topicInput.value = id;
24-
}
259

2610
pills.forEach(function (pill) {
2711
pill.addEventListener('click', function () {
28-
selectTopic(pill.getAttribute('data-topic'));
12+
var id = pill.getAttribute('data-topic');
13+
pills.forEach(function (other) {
14+
other.setAttribute('aria-pressed', String(other === pill));
15+
});
16+
topicInput.value = id;
2917
});
3018
});
31-
32-
form.addEventListener('submit', function (event) {
33-
event.preventDefault();
34-
var pill = currentPill();
35-
sentTopic.textContent = pill ? pill.textContent : '';
36-
form.hidden = true;
37-
sent.hidden = false;
38-
sent.querySelector('h2').focus({ preventScroll: true });
39-
});
40-
41-
reset.addEventListener('click', function () {
42-
form.reset();
43-
selectTopic(pills[0].getAttribute('data-topic'));
44-
sent.hidden = true;
45-
form.hidden = false;
46-
form.querySelector('input:not([type="hidden"])').focus();
47-
});
4819
})();

‎src/App/assets/scss/components/_contact.scss‎

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,38 @@ html[data-theme="dark"] .contact-page {
284284
}
285285
}
286286

287-
.contact-consent {
288-
display: flex;
289-
align-items: flex-start;
290-
gap: 10px;
291-
font-size: 14px;
287+
.contact-error {
288+
margin: 0;
289+
font-size: 13px;
290+
color: var(--rose);
291+
}
292+
293+
.contact-alert {
294+
margin: 0;
295+
padding: 14px 16px;
296+
border-radius: 8px;
297+
border: 1px solid;
298+
font-size: 14.5px;
292299
line-height: 1.55;
293-
color: var(--text-muted);
294-
cursor: pointer;
295300

296-
input {
297-
width: 18px;
298-
height: 18px;
299-
margin: 2px 0 0;
300-
flex-shrink: 0;
301-
accent-color: var(--amber);
301+
a {
302+
color: inherit;
303+
text-decoration: underline;
302304
}
303305
}
304306

307+
.contact-alert-success {
308+
color: var(--teal);
309+
background: var(--teal-dim);
310+
border-color: var(--teal);
311+
}
312+
313+
.contact-alert-error {
314+
color: var(--rose);
315+
background: var(--rose-dim);
316+
border-color: var(--rose);
317+
}
318+
305319
.contact-form-foot {
306320
display: flex;
307321
align-items: center;
@@ -323,61 +337,6 @@ html[data-theme="dark"] .contact-page {
323337
}
324338
}
325339

326-
.contact-sent {
327-
min-height: 560px;
328-
display: flex;
329-
flex-direction: column;
330-
justify-content: center;
331-
gap: 18px;
332-
333-
&[hidden] {
334-
display: none;
335-
}
336-
337-
h2 {
338-
font-size: 28px;
339-
line-height: 1.2;
340-
}
341-
342-
p {
343-
max-width: 460px;
344-
font-size: 16.5px;
345-
line-height: 1.7;
346-
}
347-
348-
strong {
349-
color: var(--text);
350-
font-weight: 600;
351-
}
352-
353-
.btn {
354-
height: 44px;
355-
padding: 0 18px;
356-
color: var(--text-muted);
357-
358-
&:hover {
359-
border-color: var(--amber);
360-
color: var(--text);
361-
}
362-
}
363-
}
364-
365-
.contact-sent-icon {
366-
width: 48px;
367-
height: 48px;
368-
border-radius: var(--radius);
369-
display: flex;
370-
align-items: center;
371-
justify-content: center;
372-
background: var(--teal-dim);
373-
color: var(--teal);
374-
375-
svg {
376-
width: 22px;
377-
height: 22px;
378-
}
379-
}
380-
381340
/* FAQ */
382341
.contact-faq-layout {
383342
display: grid;
@@ -488,8 +447,4 @@ html[data-theme="dark"] .contact-page {
488447
justify-content: center;
489448
}
490449
}
491-
492-
.contact-sent {
493-
min-height: 360px;
494-
}
495450
}

‎src/App/src/ConfigProvider.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Dot\Cache\Adapter\ArrayAdapter;
1212
use Dot\Cache\Adapter\FilesystemAdapter;
1313
use Light\App\DBAL\Types\UuidType;
14+
use Light\App\Factory\ContactServiceFactory;
1415
use Light\App\Factory\EntityListenerResolverFactory;
1516
use Light\App\Factory\FeedGeneratorFactory;
1617
use Light\App\Factory\GetFeedViewHandlerFactory;
@@ -24,13 +25,16 @@
2425
use Light\App\Factory\MarkdownExtensionFactory;
2526
use Light\App\Factory\MarkdownRuntimeLoaderFactory;
2627
use Light\App\Factory\PackageGeneratorFactory;
28+
use Light\App\Factory\PostContactCreateHandlerFactory;
2729
use Light\App\Factory\SitemapGeneratorFactory;
2830
use Light\App\Handler\GetFeedViewHandler;
2931
use Light\App\Handler\GetIndexViewHandler;
3032
use Light\App\Handler\GetMarkdownArticleHandler;
3133
use Light\App\Handler\GetPackagesViewHandler;
3234
use Light\App\Handler\GetSitemapViewHandler;
35+
use Light\App\Handler\PostContactCreateHandler;
3336
use Light\App\Resolver\EntityListenerResolver;
37+
use Light\App\Service\ContactService;
3438
use Light\App\Service\FeedGenerator;
3539
use Light\App\Service\GitHubClient;
3640
use Light\App\Service\GitHubClientInterface;
@@ -142,6 +146,8 @@ public function getDependencies(): array
142146
GetMarkdownArticleHandler::class => GetMarkdownArticleHandlerFactory::class,
143147
GetSitemapViewHandler::class => GetSitemapViewHandlerFactory::class,
144148
GetPackagesViewHandler::class => GetPackagesViewHandlerFactory::class,
149+
PostContactCreateHandler::class => PostContactCreateHandlerFactory::class,
150+
ContactService::class => ContactServiceFactory::class,
145151
FeedGenerator::class => FeedGeneratorFactory::class,
146152
SitemapGenerator::class => SitemapGeneratorFactory::class,
147153
GitHubClient::class => GitHubClientFactory::class,

0 commit comments

Comments
 (0)