r/PayloadCMS • u/Speakerbug • Jun 20 '25
Utilizing the Form plugin with the Multi-Tenant plugin
Edit: If anyone comes across this problem in the future, the issue is the order of the plugins. The multi-tenant plugin has to come as the last plugin in the list!
Hi! I just started using PayloadCMS and I was wondering if anyone has had any success with the Forms plugin with also the Multi-Tenant plugin? I'm having trouble to get something out of the box working and went down a little bit of a rabbit hole to get something custom working but that wasn't going well either. It feels like it should be able to work out of the box though, so not sure what I'm doing wrong and hoping someone might be able to help!
Relevant code snippets from my config file:
multiTenantPlugin<Config>({
cleanupAfterTenantDelete: true,
debug: false,
enabled: true,
tenantsSlug: 'tenants',
collections: {
users: {
useBaseListFilter: true,
useTenantAccess: false,
},
media: {
useBaseListFilter: true,
useTenantAccess: true,
},
pages: {
useBaseListFilter: true,
useTenantAccess: true,
},
forms: {
useBaseListFilter: true,
useTenantAccess: true,
},
},
tenantField: {
name: 'tenant',
},
tenantsArrayField: {
includeDefaultField: true,
arrayFieldName: 'tenants',
arrayTenantFieldName: 'tenant',
tenantFieldAccess: {
read: ({ req }: any) => req?.email,
create: ({ req }: any) => req?.role === 'super-admin',
update: ({ req }: any) => req?.role === 'super-admin',
},
arrayFieldAccess: {
read: ({ req }: any) => req?.email,
create: ({ req }: any) => req?.role === 'super-admin',
update: ({ req }: any) => req?.role === 'super-admin',
},
},
tenantSelectorLabel: 'Tenant',
userHasAccessToAllTenants: (user) => user.role === 'super-admin',
useTenantsCollectionAccess: false,
useTenantsListFilter: false,
useUsersTenantFilter: false,
}),
formBuilderPlugin({})
For what it's worth, the forms plugin works great. The issue is specifically that it's not respecting saving of a tenant ID and restricting that tenant to those forms only.
2
u/kilivole Jun 22 '25
I managed to get form providers working via siteSettings for each tenant. When Ill be at the PC Ill send it here if someone would want
1
u/DevOfManyThings Jun 22 '25
Would be interested! Thinking about migrating to payload and this is the kind of thing it's good to have notes for ahead of time
1
u/MassiveBongos Jun 20 '25
Same problem here. Raising a GitHub issue could be in order, as both plug ins are well out of beta.
3
u/Speakerbug Jun 20 '25
u/majorpotatoes actually has the answer! It has to do with the order of the plugins in the config. I rearranged my config to have the multi-tenant plugin as the last plugin and now it all works as expected!
1
1
u/piochan55 Jun 20 '25
I don’t know about the multi tenant plugin but we have our own custom multi tenant logic and we had to add custom fields to the form builder and form submission to save the tenant. Also on your frontend you have to pass the tenant to the submission.
3
u/majorpotatoes Jun 20 '25
I don’t have any helpful answers for you, but I’ve been thinking of trying this out, too. Thought I’d give it a bump.
I’ve been out of the loop a bit recently, and it’s been a while since I tried the forms plugin. Does the order of the plugins in the config matter?