diff --git a/site/controllers/contact.php b/site/controllers/contact.php index 5daf1f3..be0f585 100644 --- a/site/controllers/contact.php +++ b/site/controllers/contact.php @@ -1,21 +1,31 @@ [ - 'name' => '', - '_from' => 'email' + $form = new Form([ + 'name' => [ + 'rules' => ['required'], + 'message' => l::get('contact.message.name-invalid', 'Please enter your name.') + ], + 'email' => [ + 'rules' => ['required', 'email'], + 'message' => l::get('contact.message.email-invalid', 'Please enter a valid email address.') ], - 'actions' => [ - [ - '_action' => 'email', - 'to' => qdated(), - 'sender' => 'codesignd form ', - 'subject' => 'Message from the contact form (' . $site->title() . ')', - 'snippet' => 'email-templates/contact' - ] - ] + 'message' => [] ]); + // Disable some Uniform features + $form->withoutRedirect()->withoutFlashing(); + + if(r::is('POST')) { + $form->emailAction([ + 'to' => qdated(), + 'from' => 'codesignd form ', + 'subject' => 'Message from the contact form (' . $site->title() . ')', + 'snippet' => 'email-templates/contact' + ]); + } + return compact('form'); }; diff --git a/site/languages/de.php b/site/languages/de.php index 47e2fc4..80a622d 100644 --- a/site/languages/de.php +++ b/site/languages/de.php @@ -20,4 +20,8 @@ l::set('contact.potty', 'Bitte lasse dieses Feld leer'); l::set('contact.submit', 'Absenden'); l::set('contact.heading.email', 'E-Mail'); +l::set('contact.message.name-invalid', 'Bitte geb deinen Namen ein.'); +l::set('contact.message.email-invalid', 'Bitte geb eine gültige E-Mail-Adresse ein.'); +l::set('contact.message.success', 'Danke für deine Nachricht, ich melde mich bald bei dir.'); + l::set('qdated.error', 'Bei der Anzeige der E-Mail-Adresse ist ein Fehler aufgetreten. Bitte kontaktiere mich über Twitter und mache mich darauf aufmerksam. Danke!'); diff --git a/site/languages/en.php b/site/languages/en.php index 0a7a1ca..74d8be8 100644 --- a/site/languages/en.php +++ b/site/languages/en.php @@ -20,4 +20,8 @@ l::set('contact.potty', 'Please leave this field blank'); l::set('contact.submit', 'Submit'); l::set('contact.heading.email', 'Email'); +l::set('contact.message.name-invalid', 'Please enter your name.'); +l::set('contact.message.email-invalid', 'Please enter a valid email address.'); +l::set('contact.message.success', 'Thank you for your message, I will get back to you soon.'); + l::set('qdated.error', 'An error occured while displaying the email address. Please contact me via Twitter and tell me about this. Thank you!'); diff --git a/site/patterns b/site/patterns index 35c60ca..12acbfc 160000 --- a/site/patterns +++ b/site/patterns @@ -1 +1 @@ -Subproject commit 35c60ca0d91a6e3def4d05638fdab3ad4e523c80 +Subproject commit 12acbfc16b22be16e4d15a85607e38a7e482e129 diff --git a/site/plugins/uniform b/site/plugins/uniform index 2e60546..dcdc51f 160000 --- a/site/plugins/uniform +++ b/site/plugins/uniform @@ -1 +1 @@ -Subproject commit 2e6054672ef3a592d8a8aff264014fc6f7e9088b +Subproject commit dcdc51f44eb99d9f802b544f7408434e4ee4c0e8 diff --git a/site/snippets/email-templates/contact.php b/site/snippets/email-templates/contact.php index ec71dc5..48e52c1 100644 --- a/site/snippets/email-templates/contact.php +++ b/site/snippets/email-templates/contact.php @@ -1,6 +1,6 @@ -Name: -Email: +Name: +Email: ---- - + diff --git a/site/snippets/templates/contact.errors.php b/site/snippets/templates/contact.errors.php new file mode 100644 index 0000000..cb7ce13 --- /dev/null +++ b/site/snippets/templates/contact.errors.php @@ -0,0 +1,7 @@ +errors()) > 0): ?> + + diff --git a/site/snippets/templates/contact.php b/site/snippets/templates/contact.php index 0f1b690..949d9a6 100644 --- a/site/snippets/templates/contact.php +++ b/site/snippets/templates/contact.php @@ -3,35 +3,38 @@
-
+
- +
- +
- +
- + + -
hasMessage() && !$form->successful()): ?>echoMessage() ?>
+
+ +
- +
- hasMessage() && $form->successful()): ?> - echoMessage() ?> + success()): ?> +
diff --git a/site/templates/contact.json.php b/site/templates/contact.json.php index a9a4533..9285bd1 100644 --- a/site/templates/contact.json.php +++ b/site/templates/contact.json.php @@ -4,13 +4,20 @@ if(r::is('POST')) { $fields = []; foreach(r::data() as $field => $value) { - $fields[$field] = $form->hasError($field); + $fields[$field] = ($form->error($field) != []); + } + + // Use error or success message depending on status + if($form->success()) { + $message = l::get('contact.message.success', 'Thank you for your message, I will get back to you soon.'); + } else { + $message = snippet('templates/contact.errors', compact('form'), true); } $data = [ - 'success' => $form->successful(), + 'success' => $form->success(), 'fields' => $fields, - 'message' => $form->message() + 'message' => $message ]; echo response::json($data);