XOOPS フォーム要素
XOOPSはXoopsFormElementクラス階層を通じてフォーム要素の包括的なセットを提供します。これらの要素はHTMLレンダリング、検証、データ処理を処理します。
フォーム要素の階層
Section titled “フォーム要素の階層”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 <|-- XoopsFormDateTimeテキスト入力要素
Section titled “テキスト入力要素”XoopsFormText
Section titled “XoopsFormText”シングルラインテキスト入力:
use XoopsFormText;
$element = new XoopsFormText( caption: 'Username', name: 'username', size: 30, maxlength: 50, value: $currentValue);XoopsFormPassword
Section titled “XoopsFormPassword”マスキング付きパスワード入力:
use XoopsFormPassword;
$element = new XoopsFormPassword( caption: 'Password', name: 'password', size: 30, maxlength: 100);XoopsFormTextArea
Section titled “XoopsFormTextArea”マルチラインテキスト入力:
use XoopsFormTextArea;
$element = new XoopsFormTextArea( caption: 'Description', name: 'description', value: $currentValue, rows: 5, cols: 50);XoopsFormSelect
Section titled “XoopsFormSelect”ドロップダウンセレクト:
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”チェックボックス入力:
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”ラジオボタングループ:
use XoopsFormRadio;
$element = new XoopsFormRadio( caption: 'Status', name: 'status', value: $currentValue);
$element->addOption('draft', 'Draft');$element->addOption('published', 'Published');$element->addOption('archived', 'Archived');ファイルアップロード
Section titled “ファイルアップロード”XoopsFormFile
Section titled “XoopsFormFile”ファイルアップロード入力:
use XoopsFormFile;
$element = new XoopsFormFile( caption: 'Upload Image', name: 'image');
$element->setMaxFileSize(2 * 1024 * 1024); // 2MBXoopsFormDateTime
Section titled “XoopsFormDateTime”日付/時刻ピッカー:
use XoopsFormDateTime;
$element = new XoopsFormDateTime( caption: 'Publish Date', name: 'publish_date', size: 15, value: time());XoopsFormHidden
Section titled “XoopsFormHidden”隠しフィールド:
use XoopsFormHidden;
$element = new XoopsFormHidden('article_id', $articleId);XoopsFormLabel
Section titled “XoopsFormLabel”表示のみのラベル:
use XoopsFormLabel;
$element = new XoopsFormLabel( caption: 'Created By', value: $authorName);XoopsFormButton
Section titled “XoopsFormButton”フォームボタン:
use XoopsFormButton;
// サブミットボタン$submit = new XoopsFormButton('', 'submit', 'Save', 'submit');
// リセットボタン$reset = new XoopsFormButton('', 'reset', 'Reset', 'reset');要素カスタマイズ
Section titled “要素カスタマイズ”CSSクラスを追加
Section titled “CSSクラスを追加”$element->setExtra('class="form-control custom-class"');カスタム属性を追加
Section titled “カスタム属性を追加”$element->setExtra('data-validate="required" placeholder="Enter text..."');$element->setDescription('Enter a unique username (3-20 characters)');関連ドキュメント
Section titled “関連ドキュメント”- Forms Overview
- Form Validation
- Custom Renderers