Building sites
Settings and forms
Site-wide values the client edits, and forms that collect enquiries without a server of your own.
Settings
Settings are named groups in site.json, each its own form in the client panel. Fields use the blueprint field vocabulary, except relation.
site.json
"settings": {
"company": {
"label": "Company details",
"description": "Appears in your site's footer and on your contact page.",
"editableBy": "editor",
"fields": [
{ "name": "name", "type": "text", "required": true },
{ "name": "phone", "type": "text" },
{ "name": "email", "type": "text" }
]
},
"sharing": {
"label": "Sharing",
"fields": [ { "name": "og_image", "type": "media", "accept": ["image"] } ]
}
}
editableByiseditororadmin, and admin when left out. Put what an editor should change (a phone number) and what only an admin should (the default sharing image) in different groups.- Templates read
setting('company.phone'), which is null when unset, never an error. - Patterns elsewhere (form notifications, structured data, SEO) refer to a setting as
{setting.company.email}.
Forms
Forms are defined in site.json and post to the platform, so they work on a static site with no server of your own.
site.json
"forms": {
"contact": {
"label": "Contact form",
"fields": [
{ "name": "name", "type": "text", "label": "Your name", "required": true },
{ "name": "email", "type": "email", "label": "Email address", "required": true },
{ "name": "message", "type": "textarea", "label": "How can we help?", "required": true, "maxLength": 5000 }
],
"notify": ["{setting.company.email}"],
"replyTo": "email",
"keepFor": 365
}
}
- Field types:
text,email,tel,textarea,select,checkboxandfile. notifytakes addresses or settings, so the client controls where enquiries go.replyTonames an email field, so replying to the notification replies to the sender.keepForis how many days enquiries are kept (365 by default). There is no "forever".- A
filefield takes one file of up to 10 MB, checked by its contents, kept privately with the enquiry and never attached to emails. manageadds fields the client uses to track enquiries (a status, a next step, notes) that visitors never see.
Rendering a form
@if ($form = $site->form('contact'))
<form method="post" action="{{ $form->action }}" enctype="{{ $form->enctype }}">
{{ $form->honeypot() }}
<input type="hidden" name="_redirect" value="{{ $entry->url() }}#sent">
<input type="hidden" name="_page" value="{{ $entry->url() }}">
@foreach ($form->fields as $field)
<label for="f-{{ $field->name }}">{{ $field->label }}</label>
<input id="f-{{ $field->name }}" name="{{ $field->name }}"
type="{{ $field->type }}" @required($field->required)>
@endforeach
<button>Send</button>
</form>
@endif
The form works with no JavaScript (a normal post and redirect). To send it in place, post it with fetch and an Accept: application/json header: you get {"ok": true}, or a 422 with errors. For a form with a file field, send new FormData(form) as it is.