### Product Field Configuration Example Source: https://github.com/verbb/formie/blob/craft-5/src/templates/integrations/feedme/fields/products.html Example of how to configure the product field, including default settings for element selection. ```html {# Available Variables #} {# Attributes: #} {# type, name, handle, instructions, attribute, default, feed, feedData #} {# Fields: #} {# name, handle, instructions, feed, feedData, field, fieldClass #} {% import 'feed-me/\_macros' as feedMeMacro %} {% import '\_includes/forms' as forms %} {% if field is defined %} {% set default = default ?? { type: 'elementselect', options: { elementType: fieldClass.elementType, selectionLabel: "Default Product"|t('feed-me'), sources: field.sources ?? '\*', }, } %} {% endif %} {% extends 'feed-me/\_includes/fields/\_base' %} ``` -------------------------------- ### Install Formie via Composer Source: https://github.com/verbb/formie/blob/craft-5/docs/get-started/installation-setup.md Install Formie using Composer and then install it within Craft CMS. ```shell cd /path/to/project ``` ```shell composer require verbb/formie && php craft plugin/install formie ``` -------------------------------- ### Page Start Hook Example Source: https://github.com/verbb/formie/blob/craft-5/docs/developers/hooks.md This hook allows inserting content at the start of a page, before the page legend. You can modify the context or return a string for rendering. ```php Craft::$app->getView()->hook('formie.page.start', function(array &$context) { // Add a variable to be accessible in the context object. $context['foo'] = 'bar'; // Optionally return a string return '
Hey!
'; }); ``` -------------------------------- ### Complete Form Template Example Source: https://github.com/verbb/formie/blob/craft-5/docs/theming/custom-rendering.md A comprehensive example demonstrating how to fetch a form, register assets, handle submissions, display messages and errors, and render form fields with custom attributes. ```twig {# Fetch the form we require #} {% set form = craft.formie.forms.handle('contactUs').one() %} {# Ensure the CSS/JS is rendered, according to the Form Template location #} {% do craft.formie.registerAssets(form.handle) %} {# Fetch the current submission - if there is one #} {% set submission = form.getCurrentSubmission() %} {% set submitted = craft.formie.plugin.service.getFlash(form.id, 'submitted') %} {# Show any error or success messages for the submission #} {% set flashNotice = craft.formie.plugin.service.getFlash(form.id, 'notice') %} {% set flashError = craft.formie.plugin.service.getFlash(form.id, 'error') %} {% if flashNotice %}Hey!
'; }); ``` -------------------------------- ### Example Email Marketing Integration Source: https://github.com/verbb/formie/blob/craft-5/docs/developers/custom-integration.md This example demonstrates how to create a custom email marketing integration by extending the `EmailMarketing` class. It includes methods for display name, icon, description, settings HTML, fetching form settings, and sending payloads. ```php getAssetManager()->getPublishedUrl("@modules/mymodule/resources/icon.svg", true); } public function getDescription(): string { return Craft::t('formie', 'This is an example email marketing integration.'); } public function getSettingsHtml(): string { $variables = $this->getSettingsHtmlVariables(); return Craft::$app->getView()->renderTemplate('path/to/settings', $variables); } public function getFormSettingsHtml($form): string { $variables = $this->getFormSettingsHtmlVariables($form); return Craft::$app->getView()->renderTemplate('path/to/form-settings', $variables); } public function fetchFormSettings() { $settings = []; // Fetch your lists from your provider's API $lists = $this->request('GET', 'lists'); foreach ($lists as $list) { // Fetch your lists' fields from your provider's API $fields = $this->request('GET', 'fields'); // Add some standard fields not included from the API $listFields = [ new IntegrationField([ 'handle' => 'email', 'name' => Craft::t('formie', 'Email'), 'required' => true, ]), ]; // Add the custom fields to our collection foreach ($fields as $key => $field) { $listFields[] = new IntegrationField([ 'handle' => $field['id'], 'name' => $field['name'], 'type' => $field['type'], ]); } // Add a new collection to our settings, including fields specific for it $settings['lists'][] = new IntegrationCollection([ 'id' => $list['id'], 'name' => $list['name'], 'fields' => $listFields, ]); } return new IntegrationFormSettings($settings); } public function sendPayload(Submission $submission): bool { // Fetch the form settings for our field mapping $fieldValues = $this->getFieldMappingValues($submission, $this->fieldMapping); // Construct a payload to send $payload = [ 'listId' => $this->listId, 'contact' => $fieldValues, ]; // Send the payload to our API endpoint via POST request. This also handles the before/after sending payload // events, which we can check on next $response = $this->deliverPayload($submission, 'subscribe', $payload); // The response might have failed, or an event returned this as invalid if ($response === false) { return false; } return true; } } ``` -------------------------------- ### Custom Automation Integration Example Source: https://github.com/verbb/formie/blob/craft-5/docs/developers/custom-integration.md Extends the base Automation class to create a custom integration. This example demonstrates defining display names, icons, descriptions, and custom settings HTML. It also includes methods for fetching form settings and sending payloads. ```php getAssetManager()->getPublishedUrl("@modules/mymodule/resources/icon.svg", true); } public function getDescription(): string { return Craft::t('formie', 'This is an example Automation integration.'); } public function getSettingsHtml(): string { $variables = $this->getSettingsHtmlVariables(); return Craft::$app->getView()->renderTemplate('path/to/settings', $variables); } public function getFormSettingsHtml($form): string { $variables = $this->getFormSettingsHtmlVariables($form); return Craft::$app->getView()->renderTemplate('path/to/form-settings', $variables); } public function fetchFormSettings() { // Fetch the form from our POST param $formId = Craft::$app->getRequest()->getParam('formId'); $form = Formie::$plugin->getForms()->getFormById($formId); // Generate a new submission $submission = new Submission(); $submission->setForm($form); // Populate the submission with fake data, for testing Formie::$plugin->getSubmissions()->populateFakeSubmission($submission); // Use Formie's function to generate a payload to send $payload = $this->generatePayloadValues($submission); $response = $this->getClient()->request('POST', $this->url, $payload); $json = Json::decode((string)$response->getBody()); return new IntegrationFormSettings([ 'response' => $response, 'json' => $json, ]); } public function sendPayload(Submission $submission): bool { // Generate a payload of values to send to the url $payload = $this->generatePayloadValues($submission); // Send the content to the URL $response = $this->getClient()->request('POST', $this->url, $payload); return true; } } ``` -------------------------------- ### Example Captcha Integration Source: https://github.com/verbb/formie/blob/craft-5/docs/developers/custom-integration.md Implement a custom Captcha integration by extending the `Captcha` class. This example shows how to define its handle, name, icon, description, and front-end/back-end HTML. ```php getAssetManager()->getPublishedUrl("@modules/mymodule/resources/icon.svg", true); } public function getDescription(): string { return Craft::t('formie', 'This is an example captcha.'); } public function getSettingsHtml(): string { $variables = $this->getSettingsHtmlVariables(); return Craft::$app->getView()->renderTemplate('path/to/settings', $variables); } public function getFrontEndHtml(Form $form, $page = null): string { return ''; } public function getFrontEndJsVariables(Form $form, $page = null) { $src = Craft::$app->getAssetManager()->getPublishedUrl('path-to-js.js', true); $onload = 'new MyCustomFunction();'; return [ 'src' => $src, 'onload' => $onload, ]; } public function validateSubmission(Submission $submission): bool { // Check the provided value $value = Craft::$app->getRequest()->post('example-captcha'); if ($value !== 'Testing captcha') { return false; } return true; } } ``` -------------------------------- ### Example Email Content Variables Source: https://github.com/verbb/formie/blob/craft-5/docs/feature-tour/email-notifications.md Demonstrates how to pull dynamic content from Craft CMS and form submissions into email notifications. This example shows common fields like 'First Name', 'Last Name', 'Email', and 'Message'. ```html **First Name:** Peter **Last Name:** Sherman **Email** psherman@wallaby.com **Message** Just wanted to say, I love the new website! ``` -------------------------------- ### Comparison Operators Examples Source: https://github.com/verbb/formie/blob/craft-5/docs/feature-tour/fields.md Shows examples of comparison operators used in the Calculations field for validating or comparing field values. These operators include equality, inequality, and greater/less than comparisons. ```Calculations {field1} == {field2} ``` ```Calculations {field1} > {field2} ``` -------------------------------- ### Create a Submission Query (PHP) Source: https://github.com/verbb/formie/blob/craft-5/docs/getting-elements/submission-queries.md Instantiate a new submission query object in PHP. This is the starting point for fetching submissions. ```php // Create a new submission query $myQuery = \verbb\formie\elements\Submission::find(); ``` -------------------------------- ### Text Field with Validation Source: https://github.com/verbb/formie/blob/craft-5/docs/developers/custom-field.md Example of creating a text field using SchemaHelper, including a label, help text, name, and validation rules. The validation requires the field to be filled and start with 'Some Value'. ```php SchemaHelper::textField([ 'label' => Craft::t('formie', 'Placeholder'), 'help' => Craft::t('formie', 'The text that will be shown if the field doesn’t have a value.'), 'name' => 'placeholder', 'validation' => 'required|starts_with:Some Value' ]), ``` -------------------------------- ### Create a Submission Query Source: https://github.com/verbb/formie/blob/craft-5/docs/getting-elements/submission-queries.md Instantiate a new submission query object. This is the starting point for fetching submissions. ```twig {# Create a new submission query #} {% set myQuery = craft.formie.submissions() %} ``` -------------------------------- ### Example Address Provider Implementation Source: https://github.com/verbb/formie/blob/craft-5/docs/developers/custom-integration.md This PHP code demonstrates how to create a custom Address Provider by extending the `AddressProvider` class. It includes methods for display name, icon URL, description, settings HTML, and front-end HTML/JavaScript variables. ```php getAssetManager()->getPublishedUrl("@modules/mymodule/resources/icon.svg", true); } public function getDescription(): string { return Craft::t('formie', 'This is an example address provider.'); } public function getSettingsHtml(): string { $variables = $this->getSettingsHtmlVariables(); return Craft::$app->getView()->renderTemplate('path/to/settings', $variables); } public function getFrontEndHtml($field, $options): string { return ''; } public function getFrontEndJsVariables(Form $form, $field = null) { $src = Craft::$app->getAssetManager()->getPublishedUrl('path-to-js.js', true); $onload = 'new MyCustomFunction();'; return [ 'src' => $src, 'onload' => $onload, ]; } } ``` -------------------------------- ### Global Email Template Example Source: https://github.com/verbb/formie/blob/craft-5/docs/template-guides/email-templates.md This is an example of a global HTML email template. It acts as a wrapper for the email content and can utilize variables like siteName and contentHtml. Place this file in a designated email template folder (e.g., templates/_emails/index.html). ```twig{{ submission.title }}
{% endfor %} ``` -------------------------------- ### Populate a Form with Default Values Source: https://github.com/verbb/formie/blob/craft-5/docs/template-guides/populating-forms.md Fetch a form by its handle and then populate its fields with default values before rendering. This is the basic setup for pre-populating any form. ```twig {# Fetch the form with the handle `contactForm` #} {% set form = craft.formie.forms({ handle: 'contactForm' }).one() %} {# Sets the field with handle `text` to "Some Value" for the form #} {% do craft.formie.populateFormValues(form, { text: 'Some Value' }) %} {# Render the form after calling `populateFormValues()` #} {{ craft.formie.renderForm(form) }} ``` -------------------------------- ### Example PDF Template Source: https://github.com/verbb/formie/blob/craft-5/docs/template-guides/pdf-templates.md This is a basic Twig template for rendering PDF content. It includes variables for site name and email content. ```twig