Skip to main content

Forms

FREE!

Build premium forms in minutes.

A free WordPress drag-and-drop form builder with conditional logic, stored entries, file uploads, ratings, spam protection and email notifications. No coding and no paid tiers. Multi-step forms, payments and quizzes are on the roadmap.

This extension adds the possibility to create a forms (for e.g. a contact form). Use the drag & drop form builder to create any form you'll ever want or need.

One style for every form​

Form Styles (Theme Settings → Components → Form Styles) give fields one look everywhere: the Contact Form element picks one on its Style tab, the Newsletter element has the same choice (or "the site's default form style"), and Membership's login form follows the site's default. Edit a style once and every form wearing it changes. A site converted from another builder gets a style made from the source site's own fields.

Field types​

Besides text, email, number, website, dropdown, single and multiple choice, date and time, rating, file upload, hidden values and consent boxes:

  • Name: one "Full name" box, or first and last name side by side.
  • Phone: brings up the number keypad on phones and accepts the usual international formats.
  • Address: street, an optional second line, city, an optional region, postcode and country; the country can be filled in for the visitor.
  • Section: a heading and a short explanation between fields.
  • Page Break: splits a long form into steps, with a progress bar and Back / Next. Each step is checked before moving on, and a problem found when the form is sent opens the step it is on.
  • Range Slider: pick a number by dragging, with its value shown (for example "$450").
  • Picture Choices: options shown as image cards, one or several.
  • Ranking: put options in order with Move up / Move down.
  • Survey Grid: several statements answered on one scale, such as "Strongly disagree" to "Strongly agree".
  • Repeating Group: a few fields the visitor can fill in again with "Add another guest", between a minimum and a maximum you set. Saved as "1) Name: Ana, Age: 30; 2) Name: Leo, Age: 4".
  • Payment Method: lets the payer choose between card, PayPal and paying later.
  • Coupon: a box for a discount code, with an Apply button that shows the discount.
  • Signature: sign with a mouse, finger or pen, or type a full name instead. A drawn signature is kept privately with the entry like an uploaded file, and attached to the notification email.
  • Product: something with a price, either one item ("Registration, $50") or a choice of options with their own prices ("Half day $90 / Full day $160"). It can be always included, added with a tick, or bought in a typed quantity.
  • Amount: the visitor chooses how much: suggested amounts as buttons, their own amount, or both, with a minimum and a maximum. For donations, deposits and "pay what you like".
  • Calculated: a figure worked out from other answers, such as a total or a price per person, updated as the visitor types (see below).
  • Turnstile, hCaptcha, reCAPTCHA: human checks.

Every answer, however many boxes it uses, is stored and emailed as one readable line.

Pre-filled and personal forms​

  • Pre-fill: a field fills itself in from the logged-in visitor's account (and their CRM contact, when the CRM is active), or from the page address: ?name_1=Rosa fills the field whose name is name_1. A link in a newsletter can open a form already holding the reader's details. Developers can add their own values with the fw_ext_forms_prefill_values filter.
  • Answer piping: write a field's name in curly brackets in a label, a section or a help line, and the visitor's answer appears there as they type: "Who is coming with you, {name_1}?" reads "Who is coming with you, Rosa?".
  • One question at a time: the Contact Form's Style → Layout can show each field on its own screen, with a progress bar, Back / Next, and Enter to move on. Good for short surveys and sign-ups on phones.
  • Floating labels: the Floating Labels Form Style puts the label inside the field and lifts it out of the way when the visitor starts typing.

Prices, totals and payments​

  • Calculated fields use a formula over other answers: a field's name in curly brackets, numbers, + - * /, brackets, and round, ceil, floor, min, max. For example {product_tour} + {product_pickup} + {amount_tip} or {calc_total} / max({number_people}, 1). A Product counts as its line total, an Amount as the amount, and a choice as the last number in its text ("Airport pickup (+40)" counts 40). Shown as money or as a number. A hidden one can be a step in a bigger sum.
  • The server works every figure out again from the form itself when it is sent; a price or total the browser shows is never trusted.
  • Take payment (Contact Form → Settings → Actions) charges the total of the form's Products, Amounts and any Calculated field marked "add it to the total to pay". Each payment is kept with its entry under Form Entries, with a reference such as F-7K3QD, its method and its status.
  • Ways to pay:
    • Card through Stripe and PayPal: after sending the form, the payer pays on Stripe's or PayPal's own secure page (no card details touch your site) and comes back to your page, where a note confirms the payment. If they stop halfway, the note says nothing was charged and offers a link to try again. Each payment updates by itself when the service confirms it, fails or is refunded, and you can refund from the entry.
    • Pay later: a bank transfer, pay on arrival or an invoice. The visitor sees your instructions; you mark the payment paid (or cancelled, or refunded) on the entry.
  • Coupons: add codes in Forms Settings → Payments → Coupons: a percentage or a fixed amount, off the first payment or every payment, with an optional last day and number of uses. A Coupon field on the form lets the payer apply a code and see the discount straight away; the code is checked again when the form is sent.
  • Subscriptions: set a Product's Billing to every week, month or year. The payer pays the one-off items and the first period now, by card or PayPal, and the rest renews by itself. Every renewal appears on the entry; you can cancel from the entry, and the payer from a link you can put in their email ({subscription_cancel_link}). One form can mix one-off products with recurring ones of one billing period.
  • Let the payer choose with a Payment Method field (Card, PayPal, Pay later). Only the ways that are set up are shown.
  • Keys go in Forms Settings → Payments: Stripe's secret key and webhook signing secret, PayPal's Client ID, Secret and Webhook ID (the page shows the webhook address to paste into each service). If Membership already has keys, forms use those when these are empty.
  • Answer tags for the success message and emails: {order_total}, {order_summary}, {payment_ref}, {payment_method}, {payment_instructions}, and {payment_link} (a link to pay by card later, handy in a Pay later email), {subscription_ref}, {subscription_price}, {subscription_cancel_link}.
  • The currency is set once for every form in Forms Settings → Payments.
  • The form-type picker has an Order form and a Donation form to start from.

One payment system for the whole site​

By default a form is paid through the keys in Forms Settings → Payments. A site that also sells in other ways can let the shared Payments system take form payments too: one set of provider keys, one list of every payment, and more ways to pay.

  • Forms Settings → Payments → Payment system has three choices. Automatic (the default) uses the shared system once it is switched on, unless Forms already has payment keys or payments of its own. Forms' own payment settings and The shared Payments system fix the choice.
  • Only new payments follow it. Payments and subscriptions that exist stay where they were made, so keep Forms' own keys and webhook address for them. Payments → Settings tells you when they are no longer needed.
  • On the shared system a form can offer GCash, Maya, iDEAL and the other local methods set up in Payments → Settings: tick Local payment methods in the form's Payment Method field. Each is listed under its own name.
  • A Coupon field also accepts codes from Payments → Coupons.
  • Mark paid, Mark cancelled and Refund on an entry keep working, and the payment shows in Payments → All payments as well. Booking deposits follow the same setting, because they are paid through the booking form.
  • A subscription from a form needs Card (Stripe) or PayPal on either system.

Limits​

Contact Form → Settings → Limits:

  • Close after a number of entries, or open and close on dates (a date alone closes at the end of that day). While the form is closed your message shows instead of it, and a page left open from before is refused when it is sent.
  • Places per choice: one line per choice, such as Saturday workshop | 20. The form shows "3 places left" next to the choice, switches a full choice off, and refuses it if it is sent anyway. Places are counted from the stored entries, so deleting an entry frees its place.

Long forms, PDFs and spreadsheets​

  • Save and continue later (Settings → Options): a button next to Send lets the visitor save their answers and get an email with a link to finish later; the link fills the form in again. Saved answers are kept for the days you choose (30 by default) and removed once the form is sent. Passwords, files and drawn signatures are never saved.
  • PDF copies: every entry has a Download PDF button, and a PDF of the answers (with a drawn signature) can be attached to the notification email and to the sender's confirmation (Settings → Options → PDF copy). The title takes answer tags, such as Waiver signed by {text_name}. Latin letters, accents and the euro sign are printed; other alphabets are left out of the PDF.
  • Send to a spreadsheet (an action) adds each submission as a row in a Google Sheets spreadsheet: put a Google service account key in Forms Settings → Google Sheets, share the spreadsheet with that account, and choose the spreadsheet and tab on the form. A header row of field labels is kept up to date, and answers are written as plain text, so an answer can never run as a formula.

Quizzes​

Contact Form → Settings → Quiz turns a form into a quiz or a "which one suits you" finder:

  • Points go one answer per line: Paris = 1. To score an answer in one question only, start with the field's name: checkboxes_primes: 9 = -1. Typed answers score too, and case does not matter.
  • Results by score: each range has a title, a message, and optionally a page to send the visitor to and a CRM tag for their contact.
  • Show the result with {quiz_score}, {quiz_max}, {quiz_percent}, {quiz_result} and {quiz_message} in the success message. The score is also saved with the entry.

Form Results​

Unyson+ → Forms → Results (or See results on Entries) sums up a form's entries for any period: how often each choice was picked, the average rating and, for a 0–10 question, the NPS, a table per survey-grid statement, averages for numbers, quiz scores and results, the latest answers to open questions, and entries per week. Names, emails, phone numbers, addresses and files are never summarised.

Following up​

  • How each form performs (Form Results): how many saw the form, started it and sent it, and the field where people gave up. Only counts are kept, with no cookies and nothing anyone typed; search engines and your own logged-in editors are not counted. Turn it off in Forms Settings → Entries.
  • Unfinished entries (Settings → Options, off by default): keep what a visitor typed even if they leave without sending, so a half-finished quote request can be followed up. A short notice under the form says so. They appear under Form Entries → Unfinished and are deleted if the visitor sends the form after all.
  • On each entry: star it, assign it to someone on your team (they get an email), add notes only your team sees, reply to the sender by email, and correct an answer. Every step is kept in the entry's history, with the old answer for a correction. The list has Starred and Assigned to me views.
  • A spreadsheet by email: Forms Settings → Entries can email a CSV of the new entries every day or every week (Monday mornings). Nothing is sent when nothing came in.
  • Keep entries for…: each form can delete its entries after its own number of days (Settings → Options), instead of the site-wide period.

Showing entries on the site​

Turn what people send into content: a directory of members, listings, testimonials, an events calendar.

  1. In the form's Settings → On the site, switch on Entries can be shown on the site. Nothing is ever shown from a form until you do.
  2. Leave Approve each entry before it is shown on (the default) to check each one first. The approvers get an email with the answers and Approve / Reject links that work without logging in; the entry screen has the same buttons, and Form Entries gets a To approve list.
  3. Add an Entry View element to a page, choose the form, and list the fields to show. Pick how to show them: a table, cards, a list, a map (from a "latitude, longitude" field) or a calendar (from a date field). Add a search box, a filter on one field, and a page for each entry.

Only the fields you list are shown, and search and the filter only look at those fields, so nobody can find an entry by what it says in a field you did not choose. Uploaded files are never shown.

Letting people edit what they sent​

With Senders can edit their entry on, a logged-in person sees an Edit link next to their own entries (use an Entry View with Only the visitor's own entries). It opens the form with their answers filled in; sending it updates the entry, without a new notification. The change is kept in the entry's history, and if the form approves entries first, the edited one waits for approval again. Choose when editing stops: once the entry is approved, after a number of days, or never.

More actions​

  • Send to a webhook posts each submission to an address, as JSON or form fields, for automation tools (Zapier, Make, n8n) and other systems. With a secret, each request carries a signature header the receiver can check.
  • Create a post turns each submission into a post of any type (a testimonial, a listing, an event), as a draft for you to review by default. Answer tags fill the title and content, custom fields take key = {answer tag} lines, and an uploaded photo or the signature can become the featured image.

Where it lives in the admin​

Forms takes one item in the Unyson+ menu: Unyson+ → Forms. Its screens sit on a tab bar at the top:

TabWhat it shows
FormsYour saved forms (the form library, below).
EntriesEvery submission: filter by form, status or date, search, star, archive, export to CSV.
ResultsA form's entries summed up for a period (see Form Results above).

The sidebar keeps Forms highlighted on all three. The addresses are unchanged (admin.php?page=fw-form-entries, admin.php?page=fw-form-results), so bookmarks and links from emails still open them. Entries and Results show only to people who may read entries.

The form library​

Build a form once and show it anywhere. Unyson+ → Forms lists your saved forms with how many fields each has, how many entries it has received and which pages show it.

  • Add New opens the form-type picker, then the same builder and settings as a Contact Form element.
  • Show it on a page: add a Contact Form element and choose the form under Form Fields → Saved Form, or pick it from Your saved forms in the picker. The element keeps its own style, so the same form can look different on different pages. Edit the saved form once and every page showing it changes.
  • Save an existing form: in a Contact Form element, Save to the library turns its fields into a saved form and links the element to it.
  • Entries of a saved form are grouped under that form, whichever page they came from.
  • Duplicate, Export and Import (as a .json file) from the list, to copy a form or move it to another site.
  • History: every save is kept as a revision, so an earlier version can be compared and restored.

Sending, confirmations and spam protection​

  • No page reload. A form sends in the background and shows its result where the form is. Without JavaScript it still works the ordinary way.

  • Errors everyone can find. Each problem is written next to its field and announced by screen readers; a form with several problems shows a summary at the top, with links to each field.

  • After sending (Contact Form → Settings → Options): keep the form and show the message, replace the form with the message, go to a thank-you page, or go to any address. Messages Appear puts the sent message and any problems above the form or under the Send button.

  • Answer tags put the visitor's answers into the email subject, the success message and the thank-you address: {your_name} (a field's Field Name), {all_fields}, {site_name}, {page_title}, {page_url}, {date}. For example: New enquiry from {your_name}.

    • Field Name, under Label in every field's settings, is filled in from the label as you type ("Make/Model" becomes make_model) and kept unique. Rename it and the form's own subject and messages follow. A field left without one still answers to its automatic id (such as {text_3f2a9c1}).
    • Every setting that takes tags shows them as buttons underneath: click one to put it where your cursor is.
  • The notification email (Contact Form → Settings → Texts): a From Name such as {your_name} via {site_name} (the sending address is always the site's), and a Message Body written with tags, where {all_fields} lists every answer. Left empty, the email is the usual table of answers.

  • Notifications: one or more recipients, plus CC and BCC. With no recipient set, the site's admin email gets it. Send the notification email can be switched off for a form that only needs its stored entries, or whose action already tells you (a booking action that sends its own alert, for example).

  • Routed by answer (Contact Form → Settings → Notifications):

    • Send it to someone else, by answer: for example, when Department is Sales, send it to the sales team instead of the main address, or as well as it.
    • More notifications: extra emails with their own recipients, subject and wording, such as a short summary for a manager, or a copy to the address the visitor typed ({email_1}). Each can be sent always or only on a matching answer, and they go out even when the main notification is switched off.
    • A different "after sending": show another message or go to another page depending on an answer.

    Rules name a field by its label, as conditional fields do. A rule naming a field that does not exist never applies, so a typo cannot send mail to the wrong place.

  • Email the sender (Settings → Actions): a confirmation email to the person who sent the form. It greets them by name; a copy of their answers is a separate switch, best used with a human check on the form, since a form emails whatever address is typed into it.

  • Autofill: name, email, phone, company and address fields tell the browser what they hold, so it can fill them in.

  • Human checks: Cloudflare Turnstile (free, usually invisible) and hCaptcha fields, beside reCAPTCHA. Add the keys once under Unyson+ → Forms → Settings. A check without keys stays hidden and never blocks a visitor.

  • Spam filtering (Forms → Settings): Akismet (when its plugin is set up), blocked words, blocked email domains and a link limit. A caught message still sees the normal thank-you, so bots learn nothing; nothing is emailed and it waits under Form Entries → Spam, where Not spam restores it.

Customize Views​

  • Form Fields - Frontend form fields views can be customized in framework-customizations/extensions/forms/form-builder/items/{item-type}/views/view.php. All built-in form builder item types can be found in framework/extensions/forms/includes/option-types/form-builder/items/ directory.

    For e.g. to overwrite the view for item type text (which is located in framework/extensions/forms/includes/option-types/form-builder/items/text) create framework-customizations/extensions/forms/form-builder/items/text/views/view.php.

  • Form Fields Container - The view for the container that wraps the form fields can be customized in framework-customizations/extensions/forms/form-builder/views/items.php.

Contact Form Views​

  • Form Content - The inner contents of the <form> can be customized in framework-customizations/extensions/forms/extensions/contact-forms/views/form.php.
  • Email Content - The contents of the email that is sent after an user submitted the contact form can be customized in framework-customizations/extensions/forms/extensions/contact-forms/views/email.php.

Create Form Builder Item Type​

First, make sure you understand how the base builder works.

The Forms extension have a built-in form-builder option type (that can be found in the framework-customizations/extensions/forms/form-builder/ directory) which is used by the Contact Forms sub-extension. To create an item type for form-builder you have to look in its method called item_type_is_valid() to see what class you must extend in order to be accepted by the builder.

class FW_Option_Type_Form_Builder
{
...

/**
* @param FW_Option_Type_Builder_Item $item_type_instance
* @return bool
*/
protected function item_type_is_valid($item_type_instance)
{
return is_subclass_of($item_type_instance, 'FW_Option_Type_Form_Builder_Item');
}
}

So you have to extend the FW_Option_Type_Form_Builder_Item class and register it as a builder item type.

Below is explained how to create a simple Yes/No question radio input.

Create the framework-customizations/extensions/forms/includes/builder-items/yes-no directory.

Create framework-customizations/extensions/forms/includes/builder-items/yes-no/class-fw-option-type-form-builder-item-yes-no.php with the following contents:

class FW_Option_Type_Form_Builder_Item_Yes_No extends FW_Option_Type_Form_Builder_Item
{
/**
* The item type
* @return string
*/
public function get_type()
{
return 'yes-no';
}

/**
* The boxes that appear on top of the builder and can be dragged down or clicked to create items
* @return array
*/
public function get_thumbnails()
{
return array(
array(
'html' =>
'<div class="item-type-icon-title">'.
' <div class="item-type-icon"><span class="dashicons dashicons-editor-help"></span></div>'.
' <div class="item-type-title">'. __('Yes/No Question', 'unyson') .'</div>'.
'</div>',
)
);
}

/**
* Enqueue item type scripts and styles (in backend)
*/
public function enqueue_static()
{
$uri = fw_get_template_customizations_directory_uri('/extensions/forms/includes/builder-items/yes-no/static');

wp_enqueue_style(
'fw-form-builder-item-type-yes-no',
$uri .'/backend.css',
array(),
fw()->theme->manifest->get_version()
);

wp_enqueue_script(
'fw-form-builder-item-type-yes-no',
$uri .'/backend.js',
array('fw-events'),
fw()->theme->manifest->get_version(),
true
);

wp_localize_script(
'fw-form-builder-item-type-yes-no',
'fw_form_builder_item_type_yes_no',
array(
'l10n' => array(
'item_title' => __('Yes/No', 'unyson'),
'label' => __('Label', 'unyson'),
'toggle_required' => __('Toggle mandatory field', 'unyson'),
'edit' => __('Edit', 'unyson'),
'delete' => __('Delete', 'unyson'),
'edit_label' => __('Edit Label', 'unyson'),
'yes' => __('Yes', 'unyson'),
'no' => __('No', 'unyson'),
),
'options' => $this->get_options(),
'defaults' => array(
'type' => $this->get_type(),
'options' => fw_get_options_values_from_input($this->get_options(), array())
)
)
);

fw()->backend->enqueue_options_static($this->get_options());
}

/**
* Render item html for frontend form
*
* @param array $item Attributes from Backbone JSON
* @param null|string|array $input_value Value submitted by the user
* @return string HTML
*/
public function frontend_render(array $item, $input_value)
{
return '<pre>'. print_r($item, true) .'</pre>';
}

/**
* Validate item on frontend form submit
*
* @param array $item Attributes from Backbone JSON
* @param null|string|array $input_value Value submitted by the user
* @return null|string Error message
*/
public function frontend_validate(array $item, $input_value)
{
return 'Test error message';
}

private function get_options()
{
return array(
array(
'g1' => array(
'type' => 'group',
'options' => array(
array(
'label' => array(
'type' => 'text',
'label' => __('Label', 'unyson'),
'desc' => __('The label of the field that will be displayed to the users', 'unyson'),
'value' => __('Yes/No', 'unyson'),
)
),
array(
'required' => array(
'type' => 'switch',
'label' => __('Mandatory Field?', 'unyson'),
'desc' => __('If this field is mandatory for the user', 'unyson'),
'value' => true,
)
),
)
)
),
array(
'g2' => array(
'type' => 'group',
'options' => array(
array(
'default_value' => array(
'type' => 'radio',
'label' => __('Default Value', 'unyson'),
'choices' => array(
'' => __('None', 'unyson'),
'yes' => __('Yes', 'unyson'),
'no' => __('No', 'unyson'),
),
)
)
)
)
),
);
}
}
FW_Option_Type_Builder::register_item_type('FW_Option_Type_Form_Builder_Item_Yes_No');

Create framework-customizations/extensions/forms/includes/builder-items/yes-no/static/backend.js:

fwEvents.one('fw-builder:'+ 'form-builder' +':register-items', function(builder){
var currentItemType = 'yes-no';
var localized = window['fw_form_builder_item_type_yes_no'];

var ItemView = builder.classes.ItemView.extend({
template: _.template(
'<div class="fw-form-builder-item-style-default fw-form-builder-item-type-'+ currentItemType +'">'+
'<div class="fw-form-item-controls fw-row">'+
'<div class="fw-form-item-controls-left fw-col-xs-8">'+
'<div class="fw-form-item-width"></div>'+
'</div>'+
'<div class="fw-form-item-controls-right fw-col-xs-4 fw-text-right">'+
'<div class="fw-form-item-control-buttons">'+
'<a class="fw-form-item-control-required dashicons<% if (required) { %> required<% } %>" data-hover-tip="<%- toggle_required %>" href="#" onclick="return false;" >*</a>'+
'<a class="fw-form-item-control-edit dashicons dashicons-edit" data-hover-tip="<%- edit %>" href="#" onclick="return false;" ></a>'+
'<a class="fw-form-item-control-remove dashicons dashicons-no-alt" data-hover-tip="<%- remove %>" href="#" onclick="return false;" ></a>'+
'</div>'+
'</div>'+
'</div>'+
'<div class="fw-form-item-preview">'+
'<div class="fw-form-item-preview-label">'+
'<div class="fw-form-item-preview-label-wrapper"><label data-hover-tip="<%- edit_label %>"><%- label %></label> <span <% if (required) { %>class="required"<% } %>>*</span></div>'+
'<div class="fw-form-item-preview-label-edit"><!-- --></div>'+
'</div>'+
'<div class="fw-form-item-preview-input">'+
'<label><input type="radio" disabled <% if (default_value === \'yes\') { %>checked<% } %>> <%- yes %></label><br/>'+
'<label><input type="radio" disabled <% if (default_value === \'no\') { %>checked<% } %>> <%- no %></label>'+
'</div>'+
'</div>'+
'</div>'
),
events: {
'click': 'onWrapperClick',
'click .fw-form-item-control-edit': 'openEdit',
'click .fw-form-item-control-remove': 'removeItem',
'click .fw-form-item-control-required': 'toggleRequired',
'click .fw-form-item-preview .fw-form-item-preview-label label': 'openLabelEditor',
'change .fw-form-item-preview-input input': 'updateDefaultValueFromPreviewInput'
},
initialize: function() {
this.defaultInitialize();

// prepare edit options modal
{
this.modal = new fw.OptionsModal({
title: localized.l10n.item_title,
options: this.model.modalOptions,
values: this.model.get('options'),
size: 'small'
});

this.listenTo(this.modal, 'change:values', function(modal, values) {
this.model.set('options', values);
});

this.model.on('change:options', function() {
this.modal.set(
'values',
this.model.get('options')
);
}, this);
}

this.widthChangerView = new FwBuilderComponents.ItemView.WidthChanger({
model: this.model,
view: this
});

this.labelInlineEditor = new FwBuilderComponents.ItemView.InlineTextEditor({
model: this.model,
editAttribute: 'options/label'
});
},
render: function () {
this.defaultRender({
label: fw.opg('label', this.model.get('options')),
required: fw.opg('required', this.model.get('options')),
default_value: fw.opg('default_value', this.model.get('options')),
toggle_required: localized.l10n.toggle_required,
edit: localized.l10n.edit,
remove: localized.l10n.delete,
edit_label: localized.l10n.edit_label,
yes: localized.l10n.yes,
no: localized.l10n.no
});

if (this.widthChangerView) {
this.$('.fw-form-item-width').append(
this.widthChangerView.$el
);
this.widthChangerView.delegateEvents();
}

if (this.labelInlineEditor) {
this.$('.fw-form-item-preview-label-edit').append(
this.labelInlineEditor.$el
);
this.labelInlineEditor.delegateEvents();
}
},
openEdit: function() {
this.modal.open();
},
removeItem: function() {
this.remove();

this.model.collection.remove(this.model);
},
toggleRequired: function() {
var values = _.clone(
// clone to not modify by reference, else model.set() will not trigger the 'change' event
this.model.get('options')
);

values.required = !values.required;

this.model.set('options', values);
},
openLabelEditor: function() {
this.$('.fw-form-item-preview-label-wrapper').hide();

this.labelInlineEditor.show();

this.listenToOnce(this.labelInlineEditor, 'hide', function() {
this.$('.fw-form-item-preview-label-wrapper').show();
});
},
updateDefaultValueFromPreviewInput: function() {
var values = _.clone(
// clone to not modify by reference, else model.set() will not trigger the 'change' event
this.model.get('options')
);

values.default_value = this.$('.fw-form-item-preview-input input').val();

this.model.set('options', values);
},
onWrapperClick: function(e) {
if (!this.$el.parent().length) {
// The element doesn't exist in DOM. This listener was executed after the item was deleted
return;
}

if (!fw.elementEventHasListenerInContainer(jQuery(e.srcElement), 'click', this.$el)) {
this.openEdit();
}
}
});

var Item = builder.classes.Item.extend({
defaults: function() {
var defaults = _.clone(localized.defaults);

defaults.shortcode = fwFormBuilder.uniqueShortcode(defaults.type +'_');

return defaults;
},
initialize: function() {
this.defaultInitialize();

this.modalOptions = localized.options;

this.view = new ItemView({
id: 'fw-builder-item-'+ this.cid,
model: this
});
}
});

builder.registerItemClass(Item);
});

Create framework-customizations/extensions/forms/includes/builder-items/yes-no/static/backend.css:

/* controls */

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-controls .fw-form-item-control-buttons {
display: none;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no:hover .fw-form-item-controls .fw-form-item-control-buttons {
display: inline-block;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-controls .fw-form-item-control-buttons > a,
.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-controls .fw-form-item-control-buttons > a:hover {
text-decoration: none;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-controls .fw-form-item-control-buttons a.fw-form-item-control-required {
color: #999999;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-controls .fw-form-item-control-buttons a.fw-form-item-control-required.required {
color: #ff0000;
}

/* end: controls */


/* preview */

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-preview {
padding: 5px 0;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-preview .fw-form-item-preview-label {
padding: 5px 0 10px;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-preview .fw-form-item-preview-label span {
display: none;
}

.fw-option-type-form-builder .fw-form-builder-item-type-yes-no .fw-form-item-preview .fw-form-item-preview-label span.required {
display: inline;
color: #ff0000;
}

/* end: preview */

Include the item type by creating the framework-customizations/extensions/forms/hooks.php file with the following contents:

<?php if (!defined('FW')) die('Forbidden');

/** @internal */
function _action_theme_fw_ext_forms_include_custom_builder_items() {
require_once dirname(__FILE__) .'/includes/builder-items/yes-no/class-fw-option-type-form-builder-item-yes-no.php';
}
add_action('fw_option_type_form_builder_init', '_action_theme_fw_ext_forms_include_custom_builder_items');

At this point the item is working only in backend. If you save the form, add it in a page (or post) using Page Builder and open that page in frontend, you will see the item attributes array.

To make item working in frontend, follow the instructions below:

  • Change the frontend_render() method:
class FW_Option_Type_Form_Builder_Item_Yes_No extends FW_Option_Type_Form_Builder_Item
{

...

public function frontend_render(array $item, $input_value)
{
if (is_null($input_value)) {
$input_value = $item['options']['default_value'];
}

return fw_render_view(
$this->locate_path(
// Search view in 'framework-customizations/extensions/forms/form-builder/items/yes-no/views/view.php'
'/views/view.php',
// Use this view by default
dirname(__FILE__) .'/view.php'
),
array(
'item' => $item,
'input_value' => $input_value
)
);
}
}
  • Create the view framework-customizations/extensions/forms/includes/builder-items/yes-no/view.php:
<?php if (!defined('FW')) die('Forbidden');
/**
* @var array $item
* @var array $input_value
*/

$options = $item['options'];
?>
<div class="<?php echo esc_attr(fw_ext_builder_get_item_width('form-builder', $item['width'] .'/frontend_class')) ?>">
<div class="field-radio input-styled">
<label><?php echo fw_htmlspecialchars($item['options']['label']) ?>
<?php if ($options['required']): ?><sup>*</sup><?php endif; ?>
</label>
<div class="custom-radio">
<div class="options">
<?php
foreach (array('yes' => __('Yes', 'unyson'), 'no' => __('No', 'unyson')) as $value => $label): ?>
<?php
$choice_attr = array(
'value' => $value,
'type' => 'radio',
'name' => $item['shortcode'],
'id' => 'rand-'. fw_unique_increment(),
);

if ($input_value === $value) {
$choice_attr['checked'] = 'checked';
}
?>
<input <?php echo fw_attr_to_html($choice_attr) ?> />
<label for="<?php echo esc_attr($choice_attr['id']) ?>"><?php echo $label ?></label>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
  • Change the frontend_validate() method:
class FW_Option_Type_Form_Builder_Item_Yes_No extends FW_Option_Type_Form_Builder_Item
{

...

public function frontend_validate(array $item, $input_value)
{
$options = $item['options'];

$messages = array(
'required' => str_replace(
array('{label}'),
array($options['label']),
__('This {label} field is required', 'unyson')
),
'not_existing_choice' => str_replace(
array('{label}'),
array($options['label']),
__('{label}: Submitted data contains not existing choice', 'unyson')
),
);

if ($options['required'] && empty($input_value)) {
return $messages['required'];
}

// check if has not existing choices
if (!empty($input_value) && !in_array($input_value, array('yes', 'no'))) {
return $messages['not_existing_choice'];
}
}
}

Now the field will be displayed in frontend as a radio box and the validation will work. The submitted value will be used by the form type you chose when created the form, for e.g. the Contact Forms sub-extensions will send the value in email.

You can inspect the built-in form items to learn what possibilities for customization are available (for e.g. what methods from the extended class you can overwrite).

With the AI Assistant​

When the AI Assistant (Beta) extension is active, the AI can add forms to pages:

  • forms-describe — the field types and the ready-made starters (contact, booking, quote, registration, support, feedback, NPS, signup).
  • forms-add — a contact form from a starter and / or a list of fields (label, required, width, choices), with who receives the submissions and the button / success texts.

The AI has no access to form entries — the people who submit stay private. Try "Add a booking form with name, email, preferred date and number of guests to the Contact page."