Created
January 28, 2019 14:23
-
-
Save starckio/a7fdea21e8bd2b9d7e64bd1148e980e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title: Contact | |
preset: page | |
icon: 📮 | |
status: | |
draft: Draft | |
listed: Published | |
fields: | |
to: | |
label: Receiver (To) | |
type: email | |
placeholder: [email protected] | |
help: The email address that should be the receiver of the emails. | |
width: 1/2 | |
from: | |
label: Sender (From) | |
type: email | |
placeholder: [email protected] | |
help: The email address that will be the sender of the emails. | |
width: 1/2 | |
sidebar: | |
meta: | |
type: fields | |
fields: | |
subjects: | |
type: structure | |
fields: | |
subject: | |
type: text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Uniform\Form; | |
return function ($kirby, $page) { | |
$form = new Form([ | |
'name' => [ | |
'rules' => ['required'], | |
'message' => 'Please enter a valid name', | |
], | |
'email' => [ | |
'rules' => ['required', 'email'], | |
'message' => 'Please enter a valid email address', | |
], | |
'subject' => [], | |
'message' => [ | |
'rules' => ['required'], | |
'message' => 'Please enter a message', | |
], | |
]); | |
if ($kirby->request()->is('POST')) { | |
$to = $page->to()->value(); | |
$from = $page->from()->value(); | |
$form->emailAction([ | |
'to' => $to, | |
'from' => $from, | |
'subject' => '{{subject}} - from {{name}}.', | |
'template' => 'contact', | |
]); | |
} | |
return compact('form'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php snippet('header') ?> | |
<main class="main" role="main"> | |
<?php if ($form->success()): ?> | |
<div class="alert success"> | |
—— Success message —— | |
</div> | |
<?php else: ?> | |
<form action="<?php echo $page->url() ?>" method="POST" class="inquire-form"> | |
<div class="tfields"> | |
<div class="field<?php if ($form->error('name')): ?> error<?php endif; ?>"> | |
<input name="name" type="text" value="<?php echo $form->old('name') ?>" placeholder="Name"> | |
</div> | |
<div class="field<?php if ($form->error('email')): ?> error<?php endif; ?>"> | |
<input name="email" type="email" value="<?php echo $form->old('email') ?>" placeholder="Email"> | |
</div> | |
</div> | |
<?php if($page->subjects() != ''): ?> | |
<div class="field select"> | |
<?php $value = $form->old('subject') ?> | |
<select name="subject" id="subject" class="required"> | |
<optgroup label="Subjects"> | |
<?php foreach ($page->subjects()->yaml() as $subject): ?> | |
<option value="<?= $subject['subject'] ?>" <?php e($value==$subject['subject'], ' selected')?>><?= $subject['subject'] ?></option> | |
<?php endforeach ?> | |
</optgroup> | |
</select> | |
</div> | |
<?php else: ?> | |
<div class="honeypot"> | |
<input type="subject" id="subject" name="subject" value="New message from your website."> | |
</div> | |
<?php endif ?> | |
<div class="field<?php if ($form->error('message')): ?> error<?php endif; ?>"> | |
<textarea name="message" placeholder="Message"><?php echo $form->old('message') ?></textarea> | |
</div> | |
<?php echo csrf_field() ?> | |
<?php echo honeypot_field() ?> | |
<div class="field"> | |
<input type="submit" name="submit" value="Submit"> | |
</div> | |
</form> | |
<?php endif ?> | |
</main> | |
<?php snippet('footer') ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment