Gathering detailed insights and metrics for payload-plugin-form-builder
Gathering detailed insights and metrics for payload-plugin-form-builder
Gathering detailed insights and metrics for payload-plugin-form-builder
Gathering detailed insights and metrics for payload-plugin-form-builder
npm install payload-plugin-form-builder
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
Notice: This plugin has moved! It is now supported by PayloadCMS — see the official plugin for full details.
A plugin for Payload CMS to easily allow your admin editors to build and manage forms from the admin panel.
Core features:
forms
collection where you can:
formSubmissions
collection that:
1 yarn add @payloadcms/plugin-form-builder 2 # OR 3 npm i @payloadcms/plugin-form-builder
In the plugins
array of your Payload config, call the plugin with options:
1import { buildConfig } from 'payload/config'; 2import formBuilder from '@payloadcms/plugin-form-builder'; 3 4const config = buildConfig({ 5 collections: [ 6 { 7 slug: 'pages', 8 fields: [] 9 } 10 ], 11 plugins: [ 12 formBuilder() 13 ] 14}); 15 16export default config;
fields
An object of field types to allow your admin editors to build forms with. Pass either a boolean value or a partial Payload Block to override default settings. See Fields for more details.
fields: {
text: true,
select: true,
email: true,
state: true,
country: true,
checkbox: true,
number: true,
message: true,
payment: false
}
You can also provide your own custom field definitions by passing a new Payload Block object into fields
.
redirectRelationships
An array of collection slugs that, when enabled, are populated as options in form redirect fields.
redirectRelationships: ['pages']
handlePayment
A beforeChange hook that is called upon form submissions. You can integrate into any third-party payment processing API here. There is a getPaymentTotal
function that will calculate the total cost after all conditions have been applied.
import { getPaymentTotal } from '@payloadcms/plugin-form-builder';
...
handlePayment: async ({ form, submissionData }) => {
// first calculate the price
const paymentField = form.fields?.find((field) => field.blockType === 'payment');
const price = getPaymentTotal({
basePrice: paymentField.basePrice,
priceConditions: paymentField.priceConditions,
fieldValues: submissionData,
});
// then asynchronously process the payment here
}
beforeEmail
A beforeChange hook that is called just after emails are prepared, but before they are sent. This is a great place to inject your own HTML template to add custom styles.
beforeEmails: (emailsToSend) => {
// modify the emails in any way before they are sent
return emails.map((email) => ({
...email,
html: email.html // transform the html in any way you'd like (maybe wrap it in an html template?)
}))
};
formOverrides
Override anything on the form collection by sending a Payload Collection Config. Your overrides will be merged into the default forms
collection.
formOverrides: {
slug: 'contact-forms'
}
formSubmissionOverrides
By default, this plugin relies on Payload access control to restrict the update
and read
operations. This is because anyone should be able to create a form submission, even from a public-facing website - but no one should be able to update a submission one it has been created, or read a submission unless they have permission.
You can override access control and anything else on the form submission collection by sending a Payload Collection Config. Your overrides will be merged into the default formSubmissions
collection.
formSubmissionOverrides: {
slug: 'leads'
}
Each form field is defined as a Payload Block with the following subfields:
name
: stringlabel
: stringdefaultValue
: stringwidth
: stringrequired
: checkboxname
: stringlabel
: stringdefaultValue
: stringwidth
: stringoptions
: arrayrequired
: checkboxname
: stringlabel
: stringdefaultValue
: stringwidth
: stringrequired
: checkboxname
: stringlabel
: stringdefaultValue
: stringwidth
: stringrequired
: checkboxname
: stringlabel
: stringdefaultValue
: stringwidth
: stringrequired
: checkboxname
: stringlabel
: stringdefaultValue
: checkboxwidth
: stringrequired
: checkboxname
: stringlabel
: stringdefaultValue
: numberwidth
: stringrequired
: checkboxmessage
: richTextname
: stringlabel
: stringdefaultValue
: numberwidth
: stringrequired
: checkboxpriceConditions
: array
fieldToUse
: relationship, dynamically populated based on the fields in your formcondition
: string - equals
, notEquals
| hasValue
valueForOperator
: string - only if condition
is equals
or notEquals
operator
: string - add
, subtract
, multiply
, divide
valueType
: string - static
, valueOfField
value
: string - only if valueType
is static
This plugin relies on the email configuration defined in your payload.init()
. It will read from your config and attempt to send your emails using the credentials provided.
All types can be directly imported:
1import { 2 FormConfig, 3 Form, 4 FormSubmission, 5 FieldsConfig, 6 BeforePayment, 7 HandlePayment 8 } from '@payloadcms/plugin-form-builder/dist/types';
No vulnerabilities found.
No security vulnerabilities found.