XOOPS Form Elements
Overview
Section titled “Overview”XOOPS provides a comprehensive set of form elements through its XoopsFormElement class hierarchy. These elements handle rendering, validation, and data processing for web forms.
Form Element Hierarchy
Section titled “Form Element Hierarchy”classDiagram class XoopsFormElement { +getName() +getCaption() +render() +setValue() +getValue() }
XoopsFormElement <|-- XoopsFormText XoopsFormElement <|-- XoopsFormTextArea XoopsFormElement <|-- XoopsFormSelect XoopsFormElement <|-- XoopsFormCheckBox XoopsFormElement <|-- XoopsFormRadio XoopsFormElement <|-- XoopsFormButton XoopsFormElement <|-- XoopsFormHidden XoopsFormElement <|-- XoopsFormFile XoopsFormElement <|-- XoopsFormLabel XoopsFormElement <|-- XoopsFormPassword XoopsFormElement <|-- XoopsFormDateTimeText Input Elements
Section titled “Text Input Elements”XoopsFormText
Section titled “XoopsFormText”Single-line text input:
use XoopsFormText;
$element = new XoopsFormText( caption: 'Username', name: 'username', size: 30, maxlength: 50, value: $currentValue);XoopsFormPassword
Section titled “XoopsFormPassword”Password input with masking:
use XoopsFormPassword;
$element = new XoopsFormPassword( caption: 'Password', name: 'password', size: 30, maxlength: 100);XoopsFormTextArea
Section titled “XoopsFormTextArea”Multi-line text input:
use XoopsFormTextArea;
$element = new XoopsFormTextArea( caption: 'Description', name: 'description', value: $currentValue, rows: 5, cols: 50);Selection Elements
Section titled “Selection Elements”XoopsFormSelect
Section titled “XoopsFormSelect”Dropdown select:
use XoopsFormSelect;
$element = new XoopsFormSelect( caption: 'Category', name: 'category_id', value: $selected, size: 1, multiple: false);
$element->addOption(1, 'Category 1');$element->addOption(2, 'Category 2');$element->addOptionArray([ 3 => 'Category 3', 4 => 'Category 4']);XoopsFormCheckBox
Section titled “XoopsFormCheckBox”Checkbox input:
use XoopsFormCheckBox;
$element = new XoopsFormCheckBox( caption: 'Features', name: 'features', value: $selected);
$element->addOption('comments', 'Enable Comments');$element->addOption('ratings', 'Enable Ratings');XoopsFormRadio
Section titled “XoopsFormRadio”Radio button group:
use XoopsFormRadio;
$element = new XoopsFormRadio( caption: 'Status', name: 'status', value: $currentValue);
$element->addOption('draft', 'Draft');$element->addOption('published', 'Published');$element->addOption('archived', 'Archived');File Upload
Section titled “File Upload”XoopsFormFile
Section titled “XoopsFormFile”File upload input:
use XoopsFormFile;
$element = new XoopsFormFile( caption: 'Upload Image', name: 'image');
$element->setMaxFileSize(2 * 1024 * 1024); // 2MBDate and Time
Section titled “Date and Time”XoopsFormDateTime
Section titled “XoopsFormDateTime”Date/time picker:
use XoopsFormDateTime;
$element = new XoopsFormDateTime( caption: 'Publish Date', name: 'publish_date', size: 15, value: time());Special Elements
Section titled “Special Elements”XoopsFormHidden
Section titled “XoopsFormHidden”Hidden field:
use XoopsFormHidden;
$element = new XoopsFormHidden('article_id', $articleId);XoopsFormLabel
Section titled “XoopsFormLabel”Display-only label:
use XoopsFormLabel;
$element = new XoopsFormLabel( caption: 'Created By', value: $authorName);XoopsFormButton
Section titled “XoopsFormButton”Form buttons:
use XoopsFormButton;
// Submit button$submit = new XoopsFormButton('', 'submit', 'Save', 'submit');
// Reset button$reset = new XoopsFormButton('', 'reset', 'Reset', 'reset');Element Customization
Section titled “Element Customization”Adding CSS Classes
Section titled “Adding CSS Classes”$element->setExtra('class="form-control custom-class"');Adding Custom Attributes
Section titled “Adding Custom Attributes”$element->setExtra('data-validate="required" placeholder="Enter text..."');Setting Description
Section titled “Setting Description”$element->setDescription('Enter a unique username (3-20 characters)');Related Documentation
Section titled “Related Documentation”- Forms Overview
- Form Validation
- Custom Renderers