Laraform Documentation

website·Indexed 32 days ago

https://laraform.io/docs

Documentation for Laraform 1.x, a form builder featuring a wide array of elements including text, textarea, select, multiselect, date, time, and gallery inputs. It provides comprehensive guides on validation rules, nested elements, dynamic form loading, and frontend extension, along with technical references for core components like <Laraform>, <FormWizard>, and <FormTabs>.

Tokens
59.1K
Snippets
346
Records
450
Agent score
64%

What's inside Laraform

  1. Overview of Laraform form builder

    Laraform is a full-stack form builder designed for Vue.js and Laravel. It provides separate frontend and backend libraries that can be used independently or together to build complex forms. Key capabilities include:

    • Validation: Two-sided validation with 54 Laravel-compatible frontend validators.
    • Data Handling: Eloquent ORM support and multiple file uploads.
    • Form Elements: 34 built-in elements, including nested, repeatable, and translatable elements.
    • Advanced Logic: Conditional logic, form wizards, localization, and theming.
    • Extensibility: The system is designed to be extensible for custom needs.

    Common use cases include admin panels, registration and checkout forms, ERP solutions, questionnaires, and search/filtering interfaces.

  2. Use the Group Element to wrap form fields

    The Group Element creates a visual wrapper around child elements. Crucially, it keeps the resulting data structure flat, meaning the children's values are not nested under the group's key in the final form data object. To define children for a group, use the schema option.
    {
      name: {
        type: 'group',
        label: 'Name',
        schema: {
          firstname: {
            type: 'text',
            placeholder: 'First name',
            columns: 6
          },
          lastname: {
            type: 'text',
            placeholder: 'Last name',
            columns: 6
          },
        }
      }
    }
  3. Laraform Core Features Overview

    Laraform provides a standardized way to build complex forms across Laravel projects with the following capabilities:

    • Two-Sided Validation: Define rules once; they are enforced by 54 Laravel-compatible frontend validators and standard Laravel backend validation.
    • Eloquent Integration: Connect forms directly to Eloquent models for automatic relational data processing.
    • Advanced Elements: Supports nested elements (for relationships), repeatable elements (for lists), and translatable fields.
    • Dynamic Logic: Includes conditional logic to show/hide fields based on context and a Form Wizard for multi-step processes.
    • File Handling: Supports multiple file uploads with a single line of configuration.
    • Customization: Allows for custom elements, custom themes, custom validators, and custom templates.
  4. Use the Meta Element to store hidden form data

    The Meta Element is used to store data within a form that should not be rendered in the user interface. It is primarily used for holding internal state or metadata that needs to be submitted with the form.
  5. Laraform Project Status

    Laraform is currently in maintenance mode. Further details and issue tracking are available on their GitHub repository.
  6. Understand the Laraform element layout structure

    Every Laraform element consists of three distinct parts:

    1. element: The outer container.
    2. label: Renders the field label (if present).
    3. field: The container where the actual input component is placed.

    For nested elements, the field part of the parent contains the full element -> label -> field structure of the child elements.

  7. Use the Address Group Element for flat address data

    The Address Group Element provides address input functionality equivalent to the Address element, but it uses a flat data structure. This makes it behave more like a Group element, which is useful when the target data schema requires individual address fields rather than a single nested address object.
  8. Configure file metadata storage for Gallery Element

    To store detailed information about uploaded images, you must first set storeFile (the name of the child element containing the image). Once storeFile is defined, you can use the following options to map metadata to specific child elements:

    • storeSize: Element for image size.
    • storeOriginalName: Element for the original filename.
    • storeExtension: Element for the file extension.
    • storeMime: Element for the MIME type.
    • fileRules: Validation rules applied to the image element.
  9. Implement auto-processing in custom controllers

    To use Laraform's auto-processing logic inside your own controller (e.g., to add custom Authorization), use the ProcessesForm trait. You must then define a route that points to the process method of that controller.
    // Controller
    namespace App
    Http
    Controllers;
    
    use Laraform
    Traits
    ProcessesForm;
    
    class FormController extends Controller
    {
      use ProcessesForm;
    }
    
    // Route
    Route::post('/process-form', 'FormController@process');
  10. Apply conditions to nested list and group elements

    When dealing with nested elements, paths must be handled specifically:

    1. List Elements: Use the wildcard * to apply a condition to each list item separately (e.g., team.*.founder).
    2. Group Elements: Even though group data is flat, you must use the full path including the group name to reference its children (e.g., profile.is_company).
    // List Item Condition
    'background' => [
      'type' => 'textarea',
      'conditions' => [['team.*.founder', true]]
    ],
    
    // Group Condition
    'vat_number' => [
      'type' => 'text',
      'conditions' => [['profile.is_company', true]]
    ]