Have you seen our new video tutorials? Check it out!

Contact Plugin

The contact plugin helps you setup simple contact forms quickly.

Introduction

anomaly.plugin.contact

The contact plugin provides a simple API for displaying contact forms.

Properties
Key Required Type Default Description

collection

true

string

none

The collection to add the asset to.

Configuration

This plugin provides the contact form to be accessed using the form plugin function:

{{ form('contact') }}

You can configure the ContactFormBuilder just the same as any other builder using the form function. For this plugin we will focus on fields, actions, and options.

Fields

You can define fields by using the fields method:

{{ form('contact')
.fields({
    'name': {
        'label': 'Name',
        'required': true,
        'type': 'anomaly.field_type.text'
    }
})|raw }}

Naturally you would want to display more fields like subject, email, name, and maybe a field for comments. The ContactFormBuilder defines the following fields by default:

protected $fields = [
    'name'    => [
        'label'    => 'Name',
        'type'     => 'anomaly.field_type.text',
        'required' => true,
    ],
    'email'   => [
        'label'    => 'Email',
        'type'     => 'anomaly.field_type.email',
        'required' => true,
    ],
    'subject' => [
        'label'    => 'Subject',
        'type'     => 'anomaly.field_type.select',
        'required' => true,
        'config'   => [
            'options' => [
                'Support',
                'Sales',
                'Feedback',
                'Other',
            ],
        ],
    ],
    'message' => [
        'label'    => 'Message',
        'type'     => 'anomaly.field_type.textarea',
        'required' => true,
    ],
];

Actions

You can define actions by using the actions method:

{{ form('contact')
.actions({
    'submit': {
        'text': 'Say Hello!',
    }
})|raw }}

The ContactFormBuilder defines the following actions by default:

protected $actions = [
    'submit' => [
        'redirect' => false,
    ],
];

Options

Options control details of the notification message. You can set them with a fluent API:

{{ form('contact')
.to([[email protected]', [email protected]'])
.from('{email}')
.subject('You have received a message from {name}')|raw }}
Pro Tip: All options are parsed with the input data.
Options
Key Type Default Description

subject

string

Contact Request

The subject of the notification email.

to

string|array

The administrators email.

The email(s) to send the notification to.

from

string

The system email or [email protected] if not set.

The email(s) to send the notification to.

cc

string|array

none

The email(s) to CC the notification to.

bcc

string|array

none

The email(s) to BCC the notification to.

redirect

string

none

The URL or path to redirect to after sending.

success_message

string

Your message has been sent! Thank you.

The message to display after successfully sending.

error_message

string

There was a problem sending your message.

The message to display after failure to send.

message_view

string

anomaly.plugin.contact::email/contact

The view to use for the notification message.

Usage

To begin using the plugin simple use the form function.

Examples

Below are a few examples of putting the above configuration into use for real world examples.

Default Fields with Specific Recipient

<p>Contact Us!</p>

{{ form('contact')
.to([email protected]')
.from('{email}')|raw }}

Minimalistic Form with Custom Layout

{%  set form = form('contact')
.fields({
    'email': {
        'placeholder': 'What is your email?',
        'type': 'anomaly.field_type.email',
        'required': true
    },
    'comment': {
        'placeholder': 'What would you like to talk about?',
        'type': 'anomaly.field_type.textarea',
        'required': true
    }
})
.to([email protected]')
.from('{email}').get %}

{{ form.open|raw }}

<div class="form-group">
    {{ form.fields.email.input|raw }}
</div>
<div class="form-group">
    {{ form.fields.comment.input|raw }}
</div>

{{ form.actions|raw }}

{{ form.close|raw }}

Default Fields with Redirect to Thank You Page

{{ form('contact')
.redirect('thank-you')
.to([email protected]')
.from('{email}')|raw }}