Repository navigation
Reading a form as a site sees it
Written against v0.6.1.
Form::find() returns the form as it is stored, with every site's override rows and no site's values applied. Code that needs a form as one site sees it, with that site's title, email and storage choice, asks the add-on's FormResolver.
use Statamic\Facades\Form;
use UAMSWeb\MultisiteForms\Forms\FormResolver;
$form = app(FormResolver::class)->resolve(Form::find('contact'), 'es');
if ($form === null) {
// The form is not assigned to the Spanish site.
return;
}
$form->title(); // 'Contacto'
$form->store(); // false
$form->email(); // the Spanish row's email list
$form->site(); // 'es'The site can be a handle or a Statamic\Sites\Site, such as Site::current() for the site of the current request.
With contact assigned to English and Spanish, and a Spanish row setting the title to Contacto, store to false and its own recipient, the Spanish view returns those values, and the English view returns the form's own: Contact, true, and the form's email list.
resolve() returns null for a form that is not assigned to the site. A form with no sites resolves for every site.
The resolved form is read-only. Saving it throws UAMSWeb\MultisiteForms\Exceptions\ReadOnlyFormException, so one site's values never reach the form file:
The [contact] form resolved for the [es] site is read-only and cannot be saved. Resolve nothing and use Form::find('contact') to change the form itself.
To change the form, use Form::find(), or base() on the resolved form, which returns the stored form in its own class.
A submission made on the front end already carries the form resolved for its site, so $event->submission->form() in a FormSubmitted listener returns the view, with no call to the resolver needed.
- Site form view: every method of the view, and forms stored by a driver.
- Per-site title, email and store: how a site's row is read.
Home | README | Repository
Written against v0.6.1. These pages are edited in docs/wiki/ through a pull request; an edit made in the wiki is overwritten by the next publish.
Guides for site builders
- Showing a form on some sites only
- Giving each site its own title, email and store
- Checking a form's site in a template
Guides for administrators
Guides for developers
Troubleshooting
Reference
- Configuration
- Per-site title, email and store
- Control Panel access
- Attribute command
- API site filter
- Form assigned tag
- Site form view
- README
Project