Browse Source

Contact form (fix #4).

pull/13/head
Ned Zimmerman 7 years ago
parent
commit
62b16bc112
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 53
      app/controllers/App.php
  2. 24
      resources/assets/styles/components/_forms.scss
  3. 21
      resources/views/partials/contact-form.blade.php

53
app/controllers/App.php

@ -65,4 +65,57 @@ class App extends Controller
return __('Contact Us', 'aldine');
}
public function contactFormResponse()
{
if (isset($_POST['submitted'])) {
$output = [];
$name = (isset($_POST['visitor_name'])) ? $_POST['visitor_name'] : false;
$email = (isset($_POST['visitor_email'])) ? $_POST['visitor_email'] : false;
$institution = (isset($_POST['visitor_institution'])) ? $_POST['visitor_institution'] : false;
$message = (isset($_POST['message'])) ? $_POST['message'] : false;
if (!$name) {
$output['message'] = __('Name is required.', 'aldine');
$output['status'] = 'error';
$output['field'] = 'visitor_name';
} elseif (!$email) {
$output['message'] = __('Email is required.', 'aldine');
$output['status'] = 'error';
$output['field'] = 'visitor_email';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$output['message'] = __('Email is invalid.', 'aldine');
$output['status'] = 'error';
$output['field'] = 'visitor_email';
} elseif (!$institution) {
$output['message'] = __('Institution is required.', 'aldine');
$output['status'] = 'error';
$output['field'] = 'visitor_institution';
} elseif (!$message) {
$output['message'] = __('Message is required.', 'aldine');
$output['status'] = 'error';
$output['field'] = 'message';
} else {
$sent = wp_mail(
get_option('admin_email'),
__('Contact Form: ', 'aldine') . $name,
sprintf(
"From: %1\$s <%2\$s>\n%3\$s",
$name,
$email,
strip_tags($message)
),
"From: ${email}\r\nReply-To: ${email}\r\n"
);
if ($sent) {
$output['message'] = __('Your message was sent!', 'aldine');
$output['status'] = 'success';
} else {
$output['message'] = __('Your message could not be sent.', 'aldine');
$output['status'] = 'error';
}
}
return $output;
}
return false;
}
}

24
resources/assets/styles/components/_forms.scss

@ -11,8 +11,32 @@
.contact {
margin-bottom: 120px;
p {
font-size: 0.875rem;
font-weight: 600;
font-family: $font-family-sans-serif;
}
.success {
color: $dark-green;
}
.error {
color: $dark-red;
}
form {
width: 22.125rem;
.error > input[type="text"],
.error > input[type="email"],
.error > textarea {
border-bottom: solid 2px $dark-red;
}
.error > ::placeholder {
color: $dark-red;
}
}
label {

21
resources/views/partials/contact-form.blade.php

@ -1,11 +1,22 @@
<section class="contact flex flex-column justify-center items-center w-100" id="contact">
<h3 class="tc ttu">{{ $contact_form_title }}</h3>
<form action="<?php the_permalink(); ?>" method="post">
<form action="{{ network_home_url('/#contact') }}" method="post">
@if($contact_form_response)
<p class="tl mb4 w-100 {{ $contact_form_response['status'] }}">{{ $contact_form_response['message'] }}</p>
@endif
<input type="hidden" name="submitted" value="1">
<p class="flex flex-row items-center"><label class="clip" for="name">{{ __('Your name*', 'aldine' ) }}</label><input class="input-reset" type="text" placeholder="{{ __('Your name*', 'aldine' ) }}" name="name" value="{{ @esc_attr($_POST['name']) }}"></p>
<p class="flex flex-row items-center"><label class="clip" for="email">{{ __('Your email*', 'aldine' ) }}</label><input class="input-reset" type="email" placeholder="{{ __('Your email*', 'aldine' ) }}" name="email" value="{{ @esc_attr($_POST['email']) }}"></p>
<p class="flex flex-row items-center"><label class="clip" for="institution">{{ __('Your institution*', 'aldine' ) }}</label><input class="input-reset" type="text" placeholder="{{ __('Your institution*', 'aldine' ) }}" name="institution" value="{{ @esc_attr($_POST['institution']) }}"></p>
<p class="flex flex-row items-center"><label class="clip" for="content">{{ __('Your message here', 'aldine' ) }}</label><textarea class="input-reset" type="text" placeholder="{{ __('Your message here', 'aldine' ) }}" name="content">{{ @esc_textarea($_POST['content']) }}</textarea></p>
<p class="flex flex-row items-center @if(@$contact_form_response['field'] === 'visitor_name'){{ 'error' }}@endif">
<label class="clip" for="visitor_name">{{ __('Your name*', 'aldine' ) }}</label>
<input class="input-reset" type="text" placeholder="{{ __('Your name*', 'aldine' ) }}" name="visitor_name" value="@if($contact_form_response['status'] === 'error'){{ @esc_attr($_POST['visitor_name']) }}@endif"></p>
<p class="flex flex-row items-center @if(@$contact_form_response['field'] === 'visitor_email'){{ 'error' }}@endif">
<label class="clip" for="visitor_email">{{ __('Your email*', 'aldine' ) }}</label>
<input class="input-reset" type="email" placeholder="{{ __('Your email*', 'aldine' ) }}" name="visitor_email" value="@if($contact_form_response['status'] === 'error'){{ @esc_attr($_POST['visitor_email']) }}@endif"></p>
<p class="flex flex-row items-center @if(@$contact_form_response['field'] === 'visitor_institution'){{ 'error' }}@endif">
<label class="clip" for="visitor_institution">{{ __('Your institution*', 'aldine' ) }}</label>
<input class="input-reset" type="text" placeholder="{{ __('Your institution*', 'aldine' ) }}" name="visitor_institution" value="@if($contact_form_response['status'] === 'error'){{ @esc_attr($_POST['visitor_institution']) }}@endif"></p>
<p class="flex flex-row items-center @if(@$contact_form_response['field'] === 'message'){{ 'error' }}@endif">
<label class="clip" for="message">{{ __('Your message here', 'aldine' ) }}</label>
<textarea class="input-reset" type="text" placeholder="{{ __('Your message here', 'aldine' ) }}" name="message">@if($contact_form_response['status'] === 'error'){{ @esc_textarea($_POST['message']) }}@endif</textarea></p>
<p class="tc"><input class="button-reset button button-small button-secondary button-outline input-reset pointer" type="submit" value="{{ __('Send', 'aldine' ) }}" /></p>
</form>
</section>

Loading…
Cancel
Save