Fluent Forms Developer Documentation

website·Indexed 39 days ago

https://developers.fluentforms.com/

Developer resources for Fluent Forms, featuring the Fluent ORM ActiveRecord implementation for database interaction, detailed model references (such as Form, Submission, and Entry), and a comprehensive REST API guide with endpoints for forms, analytics, settings, and integrations.

Tokens
104.3K
Snippets
975
Records
1.1K
Agent score
71%

What's inside Fluent Forms

  1. Overview of the Protector Helper class

    The Protector helper is located in the \FluentForm\App\Helpers\Protector namespace. It provides a set of static methods for handling data encryption and decryption to ensure security within Fluent Forms.
  2. Introduction to Fluent Forms Query Builder

    The Fluent Forms Query Builder provides a fluent interface for creating and executing database queries. It is compatible with the PHP Laravel Framework's Query Builder, allowing developers to chain constraints and perform standard database operations.
    $query = wpFluent()->table('fluentform_forms')
                ->select(['id', 'title', 'form_fields', 'type'])
                ->where('has_payment', 1)
                ->whereBetween('created_at', ['2022-12-30 00:00:00', '2023-12-30 23:59:59'])
                ->when($formId, function ($query) use ($formId) {
                    return $query->where('id', $formId);
                })
                ->orderBy('id', 'ASC');
  3. Overview of the SubmissionMeta Model

    The SubmissionMeta model manages metadata associated with form submissions. It maps to the fluentform_submission_meta database table (prefixed with {$wpdb->prefix}) and uses id as its primary key.
    // Class: FluentForm\App\Models\SubmissionMeta
    // Extends: Model
    // Source: app/Models/SubmissionMeta.php
  4. Overview of Fluent Forms Filter Hooks

    Fluent Forms provides 331 filter hooks that allow developers to modify data and behavior. Filters operate by receiving a value, allowing the developer to change that value, and then returning the modified result to the system.
  5. Overview of the FormMeta Model

    The FormMeta model (FluentForm\App\Models\FormMeta) manages metadata associated with forms. It maps to the fluentform_form_meta database table (prefixed with {$wpdb->prefix}) and uses id as its primary key. It maintains a belongsTo relationship with the Form model via the form() method.
  6. Understand the Fluent Forms Client Side Submission Lifecycle

    When a user clicks the submit button, the client-side process executes these steps:

    1. Client-side Validation: If validation fails, the process stops and error messages are displayed.
    2. Data Preparation: Form data is gathered.
    3. UI Update: A loading icon is added to the submit button.
    4. REST API Call: A request is sent to the server.
      • If the response is a failure, the jQuery event fluentform_submission_failed is triggered on the form object.
      • If the response is a success, the process continues.
    5. Success Event: The jQuery event fluentform_submission_success is triggered on the $form object with the server response.
    6. Confirmation: The success message is shown, and the user is redirected if a redirect is configured.
    7. Cleanup: The loading icon is removed from the submit button.
  7. Use the Submission Model to manage form entries

    The Submission model (FluentForm\App\Models\Submission) manages form entry data stored in the fluentform_submissions table. It uses id as the primary key and extends the base Model class.
    use FluentForm\App\Models\Submission;
    
    // Retrieve a single submission by ID
    $submission = Submission::find($id);
    
    // Retrieve a set of submissions with conditions
    $submission_set = Submission::where('id', '>', 0)->limit(10)->get();
  8. Understand the Fluent Forms Server Side Submission Lifecycle

    The server-side submission process follows a strict five-step sequence handled primarily within the SubmissionHandlerController::submit() method.

    1. Preparing the Data: The system parses URL-encoded request data, identifies the form ID, and sanitizes the input using fluentFormSanitizer based on the form's field rules.
    2. Validating the Data: The system performs several validation checks: general submission validation, malicious attack prevention, form restrictions, nonce verification, and CAPTCHA (reCAPTCHA, hCaptcha, or Turnstile).
    3. Preparing Insert Data: The submitted data is formatted for database insertion.
    4. Inserting the Data: The data is written to the database, and integrations/notifications are triggered.
    5. Sending Response: The system determines the appropriate confirmation message and returns a JSON response to the browser.
  9. Fluent Forms Internal Directory Structure

    The plugin follows a structured architecture for developers:

    • app/: Contains the core logic, including Api (facades), Helpers, Hooks (actions/filters), Http (controllers/routes), Models (ORM), Modules (feature-specific logic), Services (business logic), and Views (PHP templates).
    • assets/: Compiled CSS/JS.
    • boot/: Application bootstrapping and bindings.
    • database/: Database migrations for forms, submissions, and logs.
    • guten_block/: React 18 source for the Gutenberg block.
    • resources/: Source files for assets (Vue 2 admin, jQuery public, SCSS) and translation files.
  10. Use IntegrationManagerHelper for custom integration settings

    The IntegrationManagerHelper class provides static helper methods used internally by integration controllers. Extension authors should use these helpers when building custom integrations that need to mirror the standard registration and settings shape of Fluent Forms.
  11. Work with multi-result sets using Fluent ORM Collections

    All multi-result sets returned by Fluent ORM (such as those retrieved via the get method or relationship access) are instances of the FluentForm\Framework\Database\Orm\Collection object. These collections are iterable, allowing them to be used in foreach loops, and support chainable map and reduce operations for advanced data manipulation.
    // Basic iteration
    $forms = FluentForm\App\Models\Form::where('status', 'published')->get();
    foreach ($forms as $form) {
        echo $form->title;
    }
    
    // Chaining operations to filter and transform
    $forms = FluentForm\App\Models\Form::all();
    $titles = $forms->reject(function ($form) {
        return $form->title === false;
    })->map(function ($form) {
        return $form->title;
    });
  12. Get overview chart data

    Retrieve data for the report overview chart via the /wp-json/fluentform/v1/report/overview-chart endpoint.
    curl -X GET \
      'https://your-site.com/wp-json/fluentform/v1/report/overview-chart' \
      -H 'X-WP-Nonce: <nonce>' \
      -H 'Content-Type: application/json'