The Userfields plugin for Cotonti (without extra fields)
The Userfields plugin for Cotonti allows creating and managing custom user fields (e.g., phone number, company name, address) without modifying the cot_users table. Manage additional user fields without creating extrafields.
Userfields Plugin for Cotonti 0.9.26
Overview
The Userfields plugin for Cotonti CMS enables the creation and management of custom user fields (e.g., phone number, company name, address, Telegram) without modifying the cot_users table. It uses dedicated tables cot_userfield_types (field types) and cot_userfield_values (field values) for scalability and ease of use. Fields seamlessly integrate into user profiles, admin panels, and templates across various modules (user lists, articles, forums, Multistore module).
Key Features
- Create, edit, and delete field types with unique codes, titles, and sort orders via the admin panel.
- Store field values in a separate table linked to user IDs.
- Edit fields in user profiles (
users.profile.tpl) and admin user editor (users.edit.tpl). - Display fields in user lists (
users.tpl), profile pages (users.details.tpl), and other templates (e.g.,page.tpl,mstore.tpl,forums.posts.tpl) using Cotonti tags. - Support for individual field tags (e.g.,
{USERFIELDS_CELL_NUMBER}), a loop for all fields (<!-- BEGIN: USERFIELDS -->), and an HTML block ({USERFIELDS_ROWS_HTML}or{USERS_ROW_FIELD_ROWS_HTML}). - Automatically save field values during profile or user data updates.
- Sort fields by
order_numparameter. - Includes test fields (
cell_number,company_name) for quick setup. - User-friendly admin panel for field management.
Field Types:
- Text
- Integer
- Currency
- Decimal
- Textarea
- Dropdown
- Radio Buttons
- Checkbox
- Date/Time
- Country
- Number Range
- Checkbox List
Requirements
- Cotonti CMS 0.9.26 or higher.
- PHP 8.4 or higher.
- Active
usersmodule. - MySQL 8.0 with InnoDB support (for foreign keys).
Installation
Prepare Files:
- Download the source code from the GitHub repository.
- Extract
cot-userfields-main.zipand upload theuserfieldsfolder to thepluginsdirectory in your Cotonti root.
Install via Admin Panel:
- Log into the Cotonti admin panel (
/admin.php). - Navigate to Administration > Extensions > User Fields.
- Find the Userfields plugin and click Install.
- The plugin creates tables
cot_userfield_typesandcot_userfield_values, adding test fields:cell_number(Mobile Phone Number, order 1) andcompany_name(Company Name, order 2). - These test fields are examples; you can delete, edit, or create new ones as needed.
- Log into the Cotonti admin panel (
Plugin Files:
userfields.setup.php(plugin configuration).userfields.install.sql(creates tables and test data).userfields.uninstall.sql(removes tables).userfields.admin.php(admin panel logic).userfields.admin.tpl(admin panel template).userfields.ru.lang.php(Russian localization).userfields.en.lang.php(English localization).userfields.functions.php(core functions).userfields.users.details.tags.php(tags for public user profile page).userfields.users.profile.tags.php(tags for profile editing).userfields.users.edit.tags.php(tags for admin user editing).userfields.users.profile.update.done.php(handles profile updates).userfields.users.edit.update.done.php(handles admin user updates).userfields.users.loop.php(displays fields in user lists).userfields.usertags.php(integrates withusertagsto display fields in any template where a username is visible, without guessing prefixes, e.g.,mstore.index.tpl,mstore.list.tpl,page.tpl,page.list.tpl,forums.posts.tpl, etc.).
Plugin Files and Structure
/userfields/
├── inc/
│ └── userfields.functions.php # Core functions
├── lang/
│ ├── userfields.ru.lang.php # Russian localization
│ ├── userfields.en.lang.php # English localization
├── setup/
│ ├── userfields.install.sql # SQL for creating tables
│ └── userfields.uninstall.sql # SQL for dropping tables
├── tpl/
│ └── userfields.admin.tpl # Template for admin panel
├── userfields.admin.php # Logic for managing fields
├── userfields.global.php # Includes language files
├── userfields.setup.php # Plugin configuration and setup
├── userfields.users.details.tags.php # Tags for public user profile page (users.details.tpl)
├── userfields.users.edit.tags.php # Tags for admin user editing (users.edit.tpl)
├── userfields.users.edit.update.done.php # Handles updates by administrators
├── userfields.users.loop.php # Displays fields in user lists (users.tpl)
├── userfields.users.profile.tags.php # Tags for profile editing (users.profile.tpl)
├── userfields.users.profile.update.done.php # Handles updates by users
└── userfields.usertags.php # Tags for integration into other modules and plugins without specific prefixes
Uninstallation:
- In admin panel: Administration > Extensions > Userfields > Uninstall.
- Executes
userfields.uninstall.sql, removing tables. - Manually delete the
plugins/userfieldsfolder.
Troubleshooting:
- Follow the installation instructions or seek help on the support forum.
Managing Fields in Admin Panel
Access the admin panel at Administration > Other > Userfields (requires admin privileges).
Interface
- Title: "Manage Additional User Fields".
- Field Types List: Table with columns: Code, Title, Sort Order, Edit, Delete.
- Forms: For adding/editing field types.
Adding a Field Type
- Click Add Field Type.
- Form:
- Code: Unique identifier (latin letters, numbers, underscore only; max 50 characters). Used in tags (e.g.,
cell_number→USERFIELDS_CELL_NUMBER). Required, must be unique. - Title: Display name (e.g., "Contact Phone"; max 100 characters). Required.
- Sort Order (order_num): Integer (e.g., 1 for first, 2 for second). Defines display order (lower number = higher priority). Required, defaults to 0.
- Code: Unique identifier (latin letters, numbers, underscore only; max 50 characters). Used in tags (e.g.,
- Click Save. Errors (duplicate code, empty fields) will be displayed.
Editing a Field Type
- Click Edit next to a field.
- Update code, title, or sort order (code must remain unique).
- Click Save. Update template tags if the code changes.
Deleting a Field Type
- Click Delete and confirm.
- Removes the field type and associated values in
cot_userfield_values(viaON DELETE CASCADE).
Field Definitions
- id: Auto-generated unique ID.
- code: Tag identifier (e.g.,
USERFIELDS_CODEfor value,USERFIELDS_CODE_TITLEfor title). - title: Display name for forms and outputs.
- order_num: Controls display order.
Filling Fields
- By Users: In profile (
users.profile.tpl), fields appear as a table with title and input. Saved on profile update. - By Admins: In user editor (
users.edit.tpl), similar table for any user. Saved on user update. - Format: Set in the plugin's admin panel. Fields are optional.
Template Integration
The plugin integrates easily with the users module and other module templates (mstore, page, forums).
Carefully read the instructions and use only one integration method for your templates.
Tags use the field code in uppercase (e.g., create cell_number in the admin panel, use {USERFIELDS_CELL_NUMBER} in templates).
All tags must be wrapped in a conditional check: <!-- IF {PHP|cot_plugin_active('userfields')} --> to verify if the plugin is installed, preventing potential errors.
For each template, there are two integration methods: loop (automatic output of all fields) and individual (custom styling for specific fields).
1. Users Module Templates
users.profile.tpl (Profile Editing) - Use Only One Method!
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
- Automatically outputs all fields with titles and input fields in a loop (i.e., a simple list of all fields created in the admin panel).
Inside
<form>(e.g., after{USERS_PROFILE_COUNTRY}), add:<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="userfields-block"> <!-- BEGIN: USERFIELDS --> <div> <label>{USERFIELDS_FIELD_TITLE}</label> {USERFIELDS_FIELD} </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
- Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number input field and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone," as set in the admin panel). Inside
<form>(e.g., after{USERS_PROFILE_COUNTRY}), add:<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <label class="userfield-title text-primary">{USERFIELDS_CELL_NUMBER_TITLE}:</label> <div class="userfield-value">{USERFIELDS_CELL_NUMBER}</div> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield text-danger"> <label class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</label> <div class="userfield-value">{USERFIELDS_COMPANY_NAME}</div> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
- Outputs specific fields with custom styling and order. Each field can be styled individually, e.g., add icons, tooltips, colors, or sizes.
users.edit.tpl (Admin User Editing) - Use Only One Method!
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
- Automatically outputs all fields with titles and input fields in a loop (i.e., a simple list of all fields created in the admin panel).
Inside
<form>(e.g., after{USERS_EDIT_COUNTRY}), add:<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="userfields-block"> <!-- BEGIN: USERFIELDS --> <div> <label>{USERFIELDS_FIELD_TITLE}</label> {USERFIELDS_FIELD} </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
- Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number input field and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone," as set in the admin panel). Inside
<form>(e.g., after{USERS_EDIT_COUNTRY}), add:<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <label class="userfield-title text-primary">{USERFIELDS_CELL_NUMBER_TITLE}:</label> <div class="userfield-value">{USERFIELDS_CELL_NUMBER}</div> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield text-danger"> <label class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</label> <div class="userfield-value">{USERFIELDS_COMPANY_NAME}</div> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
- Outputs specific fields with custom styling and order. Each field can be styled individually, e.g., add icons, tooltips, colors, or sizes.
users.details.tpl (Public Profile Page) - Use Only One Method!
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
- Automatically outputs all fields with titles and values in a loop (i.e., a simple list of all fields filled in during profile editing).
After
{USERS_DETAILS_COUNTRY_FLAG} {USERS_DETAILS_COUNTRY}, add:<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="userfields-details"> <h3>Additional Fields</h3> <!-- BEGIN: USERFIELDS_DETAILS --> <div class="userfield"> <label class="userfield-title text-success">{USERFIELDS_FIELD_TITLE}:</label> <div class="userfield-value">{USERFIELDS_FIELD}</div> </div> <!-- END: USERFIELDS_DETAILS --> </div> <!-- ENDIF -->
2. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
- Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number value and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone"). After
{USERS_DETAILS_COUNTRY_FLAG} {USERS_DETAILS_COUNTRY}, add:<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_CELL_NUMBER_TITLE}:</span> <span class="userfield-value"> <a href="tel:{USERFIELDS_CELL_NUMBER}" class="fw-semibold">{USERFIELDS_CELL_NUMBER}</a> </span> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</span> <span class="userfield-value">{USERFIELDS_COMPANY_NAME}</span> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
- Each field can be styled individually, e.g., make the phone number clickable or add icons.
users.tpl (User List) - Use Only One Method
Uses logic from userfields.users.loop.php
- Inside the user loop
<!-- BEGIN: USERS_ROW -->and<!-- END: USERS_ROW --> - For example, after
{USERS_ROW_NAME}, add:
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
Automatically outputs all fields with titles and values in a loop.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- BEGIN: USERFIELDS --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_FIELD_TITLE}:</span> <span class="userfield-value">{USERFIELDS_FIELD}</span> </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Single Tag Pre-formatted HTML Block (For Extremely Lazy Users):
Automatically outputs all fields with titles and values in a pre-formatted HTML block.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <hr> {USERS_ROW_FIELD_ROWS_HTML} </div> <!-- ENDIF -->
3. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number value and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone").<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_CELL_NUMBER_TITLE}:</span> <span class="userfield-value"> <a href="tel:{USERFIELDS_CELL_NUMBER}" class="fw-semibold">{USERFIELDS_CELL_NUMBER}</a> </span> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</span> <span class="userfield-value">{USERFIELDS_COMPANY_NAME}</span> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
2. Other Modules (via usertags)
The plugin supports integration with other modules, generating tags without specific extension prefixes for the USERFIELDS loop and individual fields (e.g., USERFIELDS_CELL_NUMBER, USERFIELDS_ROWS_HTML). The logic is handled in userfields.usertags.php, ensuring no prefixes are used.
page.tpl (Article Page) - Use Only One Method
- For example, after
{PAGE_OWNER_NAME}or in any suitable location, add:
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
Automatically outputs all fields with titles and values in a loop.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- BEGIN: USERFIELDS --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_FIELD_TITLE}:</span> <span class="userfield-value">{USERFIELDS_FIELD}</span> </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Single Tag Pre-formatted HTML Block (For Extremely Lazy Users):
Automatically outputs all fields with titles and values in a pre-formatted HTML block.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <hr> {USERFIELDS_ROWS_HTML} </div> <!-- ENDIF -->
3. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number value and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone").<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_CELL_NUMBER_TITLE}:</span> <span class="userfield-value"> <a href="tel:{USERFIELDS_CELL_NUMBER}" class="fw-semibold">{USERFIELDS_CELL_NUMBER}</a> </span> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</span> <span class="userfield-value">{USERFIELDS_COMPANY_NAME}</span> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
mstore.index.tpl / mstore.list.tpl (Product Lists) - Use Only One Method
- Inside the product loop
<!-- BEGIN: MSTORE_ROW -->and<!-- END: MSTORE_ROW -->or<!-- BEGIN: LIST_ROW -->and<!-- END: LIST_ROW --> - For example, after
{MSTORE_ROW_TITLE}, add:
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
Automatically outputs all fields with titles and values in a loop.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- BEGIN: USERFIELDS --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_FIELD_TITLE}:</span> <span class="userfield-value">{USERFIELDS_FIELD}</span> </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Single Tag Pre-formatted HTML Block (For Extremely Lazy Users):
Automatically outputs all fields with titles and values in a pre-formatted HTML block.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <hr> {USERFIELDS_ROWS_HTML} </div> <!-- ENDIF -->
3. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number value and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone").<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_CELL_NUMBER_TITLE}:</span> <span class="userfield-value"> <a href="tel:{USERFIELDS_CELL_NUMBER}" class="fw-semibold">{USERFIELDS_CELL_NUMBER}</a> </span> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</span> <span class="userfield-value">{USERFIELDS_COMPANY_NAME}</span> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
mstore.tpl (Product Page) - Use Only One Method
- For example, after
{MSTORE_OWNER_NAME}, add:
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
Automatically outputs all fields with titles and values in a loop.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- BEGIN: USERFIELDS --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_FIELD_TITLE}:</span> <span class="userfield-value">{USERFIELDS_FIELD}</span> </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Single Tag Pre-formatted HTML Block (For Extremely Lazy Users):
Automatically outputs all fields with titles and values in a pre-formatted HTML block.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <hr> {USERFIELDS_ROWS_HTML} </div> <!-- ENDIF -->
3. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number value and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone").<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_CELL_NUMBER_TITLE}:</span> <span class="userfield-value"> <a href="tel:{USERFIELDS_CELL_NUMBER}" class="fw-semibold">{USERFIELDS_CELL_NUMBER}</a> </span> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</span> <span class="userfield-value">{USERFIELDS_COMPANY_NAME}</span> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
forums.posts.tpl (Forum Posts) - Use Only One Method
1. OR Loop (Automatic Output of All Fields) - For Lazy Users:
- For example, after
{FORUMS_POSTS_ROW_USER_NAME}in the post block, add: Automatically outputs all fields with titles and values in a loop.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- BEGIN: USERFIELDS --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_FIELD_TITLE}:</span> <span class="userfield-value">{USERFIELDS_FIELD}</span> </div> <!-- END: USERFIELDS --> </div> <!-- ENDIF -->
2. OR Single Tag Pre-formatted HTML Block (For Extremely Lazy Users):
Automatically outputs all fields with titles and values in a pre-formatted HTML block.
<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <hr> {USERFIELDS_ROWS_HTML} </div> <!-- ENDIF -->
3. OR Individual (Custom Styling for Specific Fields) - Recommended, Not for Lazy Users:
Outputs specific fields with custom styling, using tags without specific prefixes (e.g.,
{USERFIELDS_CELL_NUMBER}for the phone number value and{USERFIELDS_CELL_NUMBER_TITLE}for the field title, e.g., "Contact Phone").<!-- IF {PHP|cot_plugin_active('userfields')} --> <div class="row mb-3"> <!-- IF {USERFIELDS_CELL_NUMBER} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_CELL_NUMBER_TITLE}:</span> <span class="userfield-value"> <a href="tel:{USERFIELDS_CELL_NUMBER}" class="fw-semibold">{USERFIELDS_CELL_NUMBER}</a> </span> </div> <!-- ENDIF --> <!-- IF {USERFIELDS_COMPANY_NAME} --> <div class="userfield"> <span class="userfield-title">{USERFIELDS_COMPANY_NAME_TITLE}:</span> <span class="userfield-value">{USERFIELDS_COMPANY_NAME}</span> </div> <!-- ENDIF --> </div> <!-- ENDIF -->
Support
Discuss the plugin, ask questions, or get help in the dedicated forum thread.
License
BSD License. Copyright (c) webitproff 2025.
Comments (0)
Content author
Offline
Sodium Carbonate
Last logged: 2026-07-20 04:22
- Page published: 2025-09-07 12:44
- Last update: 2025-10-26 01:27
- Language:

Русский