Download the PHP package digitalnodecom/larafields without Composer
On this page you can find all versions of the php package digitalnodecom/larafields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitalnodecom/larafields
More information about digitalnodecom/larafields
Files in digitalnodecom/larafields
Package larafields
Short Description A Laravel-powered form maker for your WordPress site.
License MIT
Informations about the package larafields
Abstract Form Maker
A flexible form maker package that allows you to define custom form groups for WordPress posts and taxonomies.
Installation
You can install this package with Composer:
After installation, you need to:
- Clear the Acorn cache:
This step is necessary for the package to be recognized by Acorn.
-
Publish the package assets and configuration:
-
Run the database migrations:
- Build the JavaScript and CSS assets:
This step compiles the JavaScript and CSS files needed for the package to function properly.
-
Add the following hooks to your current theme's
functions.php
file. - Clear the cached views
Configuration
Form groups are defined in the config/larafields.php
file. Each form group can be configured to display on specific post types or taxonomies.
Basic Structure
Core Concepts
The package uses several key terms throughout its configuration and API:
Object Types and Names
-
object_type: Defines the WordPress entity type where fields can be attached. Can be one of:
post_type
: For WordPress posts and custom post typestaxonomy
: For categories, tags, and custom taxonomiesuser
: For WordPress user profilessettings
: For option pages, term option pages, and user option pages
-
object_name: The specific identifier within an object type. Examples:
- For
post_type
: Could be "post", "page", "product", or any custom post type name - For
taxonomy
: Could be "category", "post_tag", "product_cat", or any custom taxonomy name - For
user
: Alwaysnull
- For
settings
: The slug of the options page, term options page, or user options page
- For
- object_id: The unique identifier for a specific instance:
- For posts: The post ID
- For taxonomies: The term ID
- For users: The user ID
- For settings pages: The page slug
These concepts are used throughout the package's API and configuration to precisely target where fields should be displayed and how data should be stored and retrieved.
Display Conditions
You can display form groups on any Post Type, any Term, and/or create a custom Options page:
Post Type Display
This will display the form group on the specified post type's edit screen in the WordPress Admin dashboard.
Taxonomy Display
This will display the form group on the specified taxonomy's term edit screen in the WordPress Admin dashboard.
Options Page Display
This will create a new page in the WordPress Admin dashboard with the specified title and menu entry. The form group will be rendered on this custom options page.
Term Option Page Display
This will add an action link (alongside Edit, Quick Edit, Delete, View) on the taxonomy overview page. When clicked, it opens a custom page where the form group will be rendered, with the data being related to both the selected term and taxonomy.
User Profile Display
This will display the form group on the user's "Edit Profile" page in the WordPress Admin dashboard.
User Page Display
This will add an action link (alongside Edit, Delete, and other user actions) on the Users overview page. When clicked, it opens a custom page where the form group will be rendered for the selected user.
Available Field Types
Text Field
Simple text input with optional character limit.
Date Field
Date picker input field.
DateTime Field
Date and time picker input field.
Week Field
Week picker input field.
Month Field
Month picker input field.
File Field
File upload field with image preview support. Files are stored in the default disk under the 'larafields' directory.
Textarea Field
Multiline text input with optional character limit.
Number Field
Numeric input with optional min/max values.
Multiselect Field
Dropdown field that allows selecting multiple options.
When custom_values
is set to true
, users can enter and select values that are not predefined in the options list. This is useful when you want to allow for flexible input while still providing common options.
Repeater Field
Group of fields that can be repeated multiple times.
Adding Field Groups Programmatically
You can programmatically add new field groups using the FormMaker::add_group()
method. This can be added to an action hook in your theme or plugin:
The structure follows the same format as defined in the configuration file, allowing you to specify labels, settings, and fields for your new group.
Retrieving Field Data Programmatically
You can fetch field data from the database using the FormMaker::get_field()
method. This method accepts three optional parameters:
At least one of these parameters must be provided:
$fieldKey
: The specific field key to retrieve$objectName
: The name of the object type (e.g., 'product', 'category')$objectId
: The ID of the object
The method will throw an Exception if none of these parameters are provided.
Example usage:
Extending Fields
You can modify or manipulate the existing fields using the larafields_load_fields
WordPress filter. This filter provides access to the fields collection before it's processed:
Dashboard Menu Pages
You can add custom dashboard menu pages using the larafields_load_pages
filter. This allows you to create additional admin pages for your application.
Adding Dashboard Menu Pages
Use the larafields_load_pages
filter to add new pages to the WordPress admin dashboard:
JavaScript Bundling
This package uses webpack to bundle JavaScript dependencies. The main JavaScript dependency is tom-select, which is used for the multiselect field type.
Development
To work on the JavaScript files:
- Make changes to the JavaScript files in the
resources/js
directory - Run
npm run dev
to watch for changes and automatically rebuild the JavaScript files
Production
To build the JavaScript files for production:
- Run
npm run build
to build both CSS and JavaScript files - The bundled JavaScript file will be available at
resources/js/public/larafields.js
- The tom-select CSS file will be available at
resources/js/public/css/tom-select.css
API Documentation
The package provides REST API endpoints for querying and updating forms and their data.
Query Endpoint
Authentication
The API uses Basic Authentication with WordPress Application Passwords:
- Username: Your WordPress username
- Password: Generated Application Password key
Request Body Parameters
The endpoint accepts the following parameters in the request body:
Parameter | Required | Description |
---|---|---|
object_id | No* | The ID of the object (post, term, etc.) |
object_name | No* | The name of the object type |
field_key | No* | The key of the specific field to retrieve |
*At least one of these parameters must be provided.
Field Validation
The API implements the following validation rules:
object_id
: Required if neitherobject_name
norfield_key
is providedobject_name
: Required if neitherobject_id
norfield_key
is providedfield_key
: Required if neitherobject_id
norobject_name
is provided
This means you must provide at least one of these three parameters in your request.
Query Examples
Query by Object ID
This will return all form data associated with the object ID 123.
Query by Object Name
This will return all form data associated with the object type "product".
Query by Field Key
This will return the specific field data for the field key "product_gender".
Combined Query
This will return form data that matches both the object ID 123 and object type "product".
Update Endpoint
Authentication
The API uses Basic Authentication with WordPress Application Passwords (same as the Query Endpoint).
Request Body
The request body should be a JSON object with the following properties:
Property | Required | Description |
---|---|---|
field_key | Yes | The key of the field to update |
field_value | Yes | The new value for the field |
object_id | Yes | The ID of the object (post, term, etc.) |
object_name | Yes | The name of the object type |
Example Request
Response
A successful update will return a JSON response with status 'ok':