HTML_QuickForm

PEAR::HTML_QuickForm パッケージは、HTML フォームの生成、検証および処理を行うメソッドを提供します。

イントロダクション

目次
クイックスタートガイド -- HTML_QuickForm チュートリアル
QuickHelp -- Answers to most Frequently Asked Questions
QuickForm element types -- What elements can be added to QuickForm
Migration to version 3.2 -- API changes to observe

HTML_QuickForm は、HTML フォームを便利に扱うためのライブラリです。 Javascript もしくはサーバサイドでの検証を行えますし、 いろいろな方法でカスタマイズや拡張が可能です。 HTML_QuickForm は、複数のファイルから構成されています。 中心となるファイルは、pear/HTML ディレクトリにインストールされた QuickForm.php です。 他に重要なファイルとしては、フォーム要素に関連したメソッドが記述された element.php ファイルや、要素グループを扱うメソッドが書かれた group.php ファイルが挙げられます。どちらも、他のオブジェクトと同様に、 HTML/QuickForm ディレクトリにあります。 input.php には、(text, password 等の) 入力可能なタイプのすべての要素の 共通クラスが記述されています。HTML_QuickForm には、select, text, password, checkbox, file, submit, reset, button, image, radio, hidden, textarea といった 標準的なフォーム要素のそれぞれに対応するオブジェクトが定義されています。 さらに、APIを合致させれば、独自の要素を作ることも可能です。

基本的なフォームの生成

目次
constructor HTML_QuickForm::HTML_QuickForm() -- クラスのコンストラクタ
HTML_QuickForm::addElement() -- フォームへ要素を追加する
HTML_QuickForm::apiVersion() -- 現在のAPIのバージョンを返す
HTML_QuickForm::createElement() -- 与えられた種類の要素をフォームに作成する
HTML_QuickForm::elementExists() -- フォームに要素があるか調べる
HTML_QuickForm::errorMessage() -- エラーコードからエラーメッセージを返す
HTML_QuickForm::getElementType() -- 与えられた要素の種類を返す
HTML_QuickForm::getElement() -- 要素へのリファレンスを返す
HTML_QuickForm::getMaxFileSize() -- MAX_FILE_SIZE隠し要素の値を返す
HTML_QuickForm::getRegisteredTypes() -- 登録済みの要素の種類を返す
HTML_QuickForm::isError() -- 結果がエラーかどうか知らせる
HTML_QuickForm::isTypeRegistered() -- フォーム要素の種類をサポートするか調べます
HTML_QuickForm::registerElementType() -- 新規要素タイプを登録する
HTML_QuickForm::removeElement() -- 要素の削除
HTML_QuickForm::setMaxFileSize() -- MAX_FILE_SIZEの隠し要素の値を設定する
HTML_QuickForm::updateElementAttr() -- ひとつまたは複数の要素の属性を更新する

To be written.

フォーム要素を表現したクラス群

To be written

Base classes

目次
Class Summary HTML_QuickForm_element -- Base class for form elements
constructor HTML_QuickForm_element() -- Class constructor
HTML_QuickForm_element::accept() -- Accepts a renderer
HTML_QuickForm_element::apiVersion() -- Returns the current API version
HTML_QuickForm_element::exportValue() -- Returns a 'safe' element's value (パッケージ開発者用)
HTML_QuickForm_element::freeze() -- Freezes the element
HTML_QuickForm_element::getFrozenHtml() -- Returns the value of field without HTML tags
HTML_QuickForm_element::getLabel() -- Returns the label for the element
HTML_QuickForm_element::getName() -- Returns the element name
HTML_QuickForm_element::getType() -- Returns the element type
HTML_QuickForm_element::getValue() -- Returns the value of the form element
HTML_QuickForm_element::isFrozen() -- Returns whether or not the element is frozen
HTML_QuickForm_element::onQuickFormEvent() -- Called by HTML_QuickForm whenever form event is made on this element (パッケージ開発者用)
HTML_QuickForm_element::setLabel() -- Sets a label for the element
HTML_QuickForm_element::setName() -- Sets the input field name
HTML_QuickForm_element::setPersistantFreeze() -- Sets whether element value should persist on freeze()
HTML_QuickForm_element::setValue() -- Sets the value of the form element
HTML_QuickForm_element::unfreeze() -- Unfreezes the element
Class Summary HTML_QuickForm_input -- Base class for input form elements
constructor HTML_QuickForm_input() -- Class constructor
HTML_QuickForm_input::setType() -- Sets the element type

標準的 HTML 要素

目次
Class Summary HTML_QuickForm_button -- HTML class for a button type element
constructor HTML_QuickForm_button() -- Class constructor
Class Summary HTML_QuickForm_checkbox -- HTML class for a checkbox type field
constructor HTML_QuickForm_checkbox() -- Class constructor
HTML_QuickForm_checkbox::getChecked() -- Returns whether a checkbox is checked
HTML_QuickForm_checkbox::getText() -- Returns the checkbox text
HTML_QuickForm_checkbox::setChecked() -- Sets whether a checkbox is checked
HTML_QuickForm_checkbox::setText() -- Sets the checkbox text
Class Summary HTML_QuickForm_file -- HTML class for a file type element
constructor HTML_QuickForm_file() -- Class constructor
HTML_QuickForm_file::getSize() -- Returns size of file element
HTML_QuickForm_file::getValue() -- Returns information about the uploaded file
HTML_QuickForm_file::isUploadedFile() -- Checks if the element contains an uploaded file
HTML_QuickForm_file::moveUploadedFile() -- Moves an uploaded file into the destination
HTML_QuickForm_file::setSize() -- Sets size of file element
Class Summary HTML_QuickForm_hidden -- HTML class for a hidden type element
constructor HTML_QuickForm_hidden() -- Class constructor
Class Summary HTML_QuickForm_image -- HTML class for a image type element
constructor HTML_QuickForm_image() -- Class constructor
HTML_QuickForm_image::setAlign() -- Sets alignment for image element
HTML_QuickForm_image::setBorder() -- Sets border size for image element
HTML_QuickForm_image::setSource() -- Sets source for image element
Class Summary HTML_QuickForm_password -- HTML class for a password type field
constructor HTML_QuickForm_password() -- Class constructor
HTML_QuickForm_password::setMaxlength() -- Sets maxlength of password element
HTML_QuickForm_password::setSize() -- Sets size of password element
Class Summary HTML_QuickForm_radio -- HTML class for a radio type element
constructor HTML_QuickForm_radio() -- Class constructor
HTML_QuickForm_radio::getChecked() -- Returns whether radio button is checked
HTML_QuickForm_radio::getText() -- Returns the radio text
HTML_QuickForm_radio::setChecked() -- Sets whether radio button is checked
HTML_QuickForm_radio::setText() -- Sets the radio text
Class Summary HTML_QuickForm_reset -- HTML class for a reset type element
constructor HTML_QuickForm_reset() -- Class constructor
Class Summary HTML_QuickForm_select -- Class to dynamically create an HTML SELECT
constructor HTML_QuickForm_select() -- Class constructor
HTML_QuickForm_select::addOption() -- Adds a new OPTION to the SELECT
HTML_QuickForm_select::getMultiple() -- Returns the select mutiple attribute
HTML_QuickForm_select::getPrivateName() -- Returns the element name (possibly with brackets appended)
HTML_QuickForm_select::getSelected() -- Returns an array of the selected values
HTML_QuickForm_select::getSize() -- Returns the select field size
HTML_QuickForm_select::load() -- Loads options from different types of data sources
HTML_QuickForm_select::loadArray() -- Loads the options from an associative array
HTML_QuickForm_select::loadDbResult() -- Loads the options from DB_result object
HTML_QuickForm_select::loadQuery() -- Queries a database and loads the options from the results
HTML_QuickForm_select::setMultiple() -- Sets the select mutiple attribute
HTML_QuickForm_select::setSelected() -- Sets the default values of the select box
HTML_QuickForm_select::setSize() -- Sets the select field size, only applies to 'multiple' selects
Class Summary HTML_QuickForm_submit -- HTML class for a submit type element
constructor HTML_QuickForm_submit() -- Class constructor
Class Summary HTML_QuickForm_text -- HTML class for a text field
constructor HTML_QuickForm_text -- Class constructor
HTML_QuickForm_text::setMaxlength() -- Sets maxlength of text field
HTML_QuickForm_text::setSize() -- Sets size of text field
Class Summary HTML_QuickForm_textarea -- HTML class for a textarea type field
constructor HTML_QuickForm_textarea() -- Class constructor
HTML_QuickForm_textarea::setCols() -- Sets width in cols for textarea element
HTML_QuickForm_textarea::setRows() -- Sets height in rows for textarea element
HTML_QuickForm_textarea::setWrap() -- Sets wrap type for textarea element

カスタム要素

目次
Class Summary HTML_QuickForm_advcheckbox -- HTML class for an advanced checkbox type field
constructor HTML_QuickForm_advcheckbox() -- Class constructor
HTML_QuickForm_advcheckbox::getOnclickJs() -- Create the javascript for the onclick event
HTML_QuickForm_advcheckbox::getPrivateName() -- Gets the private name for the element
HTML_QuickForm_advcheckbox::setValues() -- Sets the values used by the hidden element
Class Summary HTML_QuickForm_autocomplete -- HTML class for a text field with autocompletion feature
constructor HTML_QuickForm_autocomplete -- Class constructor
HTML_QuickForm_autocomplete::setoptions() -- Sets the options for the autocomplete input text element
Class Summary HTML_QuickForm_date -- Class for a group of elements used to input dates (and times).
constructor HTML_QuickForm_date() -- Class constructor
Class Summary HTML_QuickForm_header -- A pseudo-element used for adding headers to form
constructor HTML_QuickForm_header() -- Class constructor
Class Summary HTML_QuickForm_hiddenselect -- Creates hidden elements with select's values
constructor HTML_QuickForm_hiddenselect() -- Class constructor
Class Summary HTML_QuickForm_hierselect -- Class to dynamically create chained HTML Select elements, each select changes the content of the next.
constructor HTML_QuickForm_hierselect() -- Class constructor
HTML_QuickForm_hierselect::setMainOptions() -- Sets the options for the first select
HTML_QuickForm_hierselect::setSecOptions() -- Sets the options for the secondary select
Class Summary HTML_QuickForm_html -- A pseudo-element used for adding raw HTML to form (deprecated)
constructor HTML_QuickForm_html() -- Class constructor
Class Summary HTML_QuickForm_link -- HTML class for a link type field
constructor HTML_QuickForm_link() -- Class constructor
HTML_QuickForm_link::setHref() -- Sets the links href
Class Summary HTML_QuickForm_static -- HTML class for static data
constructor HTML_QuickForm_static() -- Class constructor
HTML_QuickForm_static::setText() -- Sets the text

グループの使用

目次
HTML_QuickForm::addGroup() -- Adds an element group
Class Summary HTML_QuickForm_group -- HTML class for a form element group
constructor HTML_QuickForm_group() -- Class constructor
HTML_QuickForm_group::getElementName() -- Returns the name of an element inside the group
HTML_QuickForm_group::getElements() -- Gets the grouped elements
HTML_QuickForm_group::getGroupType() -- Gets the group type based on its elements.
HTML_QuickForm_group::setElements() -- Sets the grouped elements

To be written.

要素値の処理

各要素の値を管理し、入力された値を処理するメソッドです。

要素値の取得、設定および処理

目次
HTML_QuickForm::setConstants() -- Sets constant form values
HTML_QuickForm::setDefaults() -- Sets default form values
HTML_QuickForm::exportValue() -- Returns the element's "safe" value
HTML_QuickForm::exportValues() -- Returns "safe" elements' values
HTML_QuickForm::getElementValue() -- Returns the element's raw value
HTML_QuickForm::getSubmitValue() -- Returns the submitted element's value
HTML_QuickForm::getSubmitValues() -- Returns the values submitted by the form
HTML_QuickForm::process() -- Performs the form data processing

検証およびフィルタ

目次
Introduction - validation and filters -- How to process submitted data
HTML_QuickForm::addRule() -- Adds a validation rule for the given field
HTML_QuickForm::addGroupRule() -- Adds a validation rule for the given group
HTML_QuickForm::addFormRule() -- 全体的な検証規則を追加する
HTML_QuickForm::isElementRequired() -- Returns whether the form element is required
HTML_QuickForm::validate() -- Performs the server side validation
HTML_QuickForm::getElementError() -- Returns error corresponding to validated element
HTML_QuickForm::setElementError() -- Set error message for a form element
HTML_QuickForm::registerRule() -- Registers a new validation rule
HTML_QuickForm::getRegisteredRules() -- Returns registered validation rules
HTML_QuickForm::isRuleRegistered() -- Returns whether the rule is supported
HTML_QuickForm::applyFilter() -- Applies a filter for the given field(s)

HTML_QuickForm は、「検証ルール」をサポートしています。 自らの検証ルールを書き、QuickForm に登録した後、自身のスクリプトからコールします。 デフォルトでは、正規表現による検証(preg_match 形式) が、検証が要求された要素についてのみ行われます。 また、クライアント側での検証を行いたい場合は、必要な javascript コードが生成されます。 サーバ側での検証は(デフォルトでは)常に行われます。

フォームへのデータのインポートや、送信されたフォームの処理に際して、フィルタを利用することができます。 フィルタは、時前に登録の必要がないことを除き、検証ルールと同様に動作します。 フィルタ関数を書き、スクリプトからコールします。 (trim, addslashes, htmlentities, などの) すべての PHP 関数が使用できますし、要素値へ再帰的に適用されます。

フォームの出力

HTML_QuickForm は、いろいろな種類のレンダラの使用が可能ですので、 フォームの出力を様々にカスタマイズすることができます。 デフォルトのレンダラを使えば、各要素の属性値やエラーメッセージ・ヘッダ・必須入力欄の表示といった点を カスタマイズできますし、独自のレンダラを書くことも可能です。

フォームのカスタマイズと出力ヘルパー

目次
HTML_QuickForm::freeze() -- "Freezes" the form's elements
HTML_QuickForm::isElementFrozen() -- Checks whether the element is frozen
HTML_QuickForm::isFrozen() -- Checks whether the form is frozen
HTML_QuickForm::setRequiredNote() -- Sets required note
HTML_QuickForm::setJsWarnings() -- Sets JavaScript warning messages
HTML_QuickForm::getRequiredNote() -- Returns the required note
HTML_QuickForm::getValidationScript() -- Returns the client side validation script
HTML_QuickForm::accept() -- レンダラを受け取る
HTML_QuickForm::defaultRenderer() -- Returns a reference to default renderer object
HTML_QuickForm::toArray() -- Returns the form's contents in an array
HTML_QuickForm::toHtml() -- Returns an HTML version of the form

基本的なレンダラ

これらのレンダラは、バージョン3.0以前の HTML_QuickForm コードを 基礎としており、動作に他のクラスを必要としません。

テンプレートベースのレンダラ

目次
HTML_QuickForm_Renderer_ArraySmarty -- A renderer for 'static' Smarty templates
constructor HTML_QuickForm_Renderer_ArraySmarty::HTML_QuickForm_Renderer_ArraySmarty() -- Constructor
HTML_QuickForm_Renderer_ArraySmarty::setErrorTemplate() -- Sets the way elements with validation errors are rendered
HTML_QuickForm_Renderer_ArraySmarty::setRequiredTemplate() -- Sets the way required elements are rendered
HTML_QuickForm_Renderer_ITDynamic -- Dynamic renderer for Integrated Templates
constructor HTML_QuickForm_Renderer_ITDynamic::HTML_QuickForm_Renderer_ITDynamic() -- Constructor
HTML_QuickForm_Renderer_ITDynamic::setElementBlock() -- Sets the block to use for element rendering
HTML_QuickForm_Renderer_ITDynamic::setHeaderBlock() -- Sets the name of a block to use for header rendering
HTML_QuickForm_Renderer_ITStatic -- Static renderer for Integrated Templates
constructor HTML_QuickForm_Renderer_ITStatic::HTML_QuickForm_Renderer_ITStatic() -- Constructor
HTML_QuickForm_Renderer_ITStatic::setErrorTemplate() -- Sets the way elements with validation errors are rendered
HTML_QuickForm_Renderer_ITStatic::setRequiredTemplate() -- Sets the way required elements are rendered
HTML_QuickForm_Renderer_QuickHtml -- Render form elements into HTML in an easy and flexible manner
constructor HTML_QuickForm_Renderer_QuickHtml::HTML_QuickForm_Renderer_QuickHtml() -- Constructor
HTML_QuickForm_Renderer_QuickHtml::toHtml() -- Returns the HTML
HTML_QuickForm_Renderer_QuickHtml::elementToHtml() -- Renders a specific form element into HTML

これらのレンダラは、フォームの HTML 出力の生成にテンプレートエンジンを使用します。

レンダラのインフラストラクチャ

目次
HTML_QuickForm_Renderer -- Abstract base class for renderers (パッケージ開発者用)
HTML_QuickForm_Renderer::startForm() -- Start visiting a form (パッケージ開発者用)
HTML_QuickForm_Renderer::finishForm() -- Finish visiting a form (パッケージ開発者用)
HTML_QuickForm_Renderer::startGroup() -- Start visiting a group (パッケージ開発者用)
HTML_QuickForm_Renderer::finishGroup() -- Finish visiting a group (パッケージ開発者用)
HTML_QuickForm_Renderer::renderElement() -- Visit an element (パッケージ開発者用)
HTML_QuickForm_Renderer::renderHeader() -- Visit a header (パッケージ開発者用)
HTML_QuickForm_Renderer::renderHidden() -- Visit a hidden element (パッケージ開発者用)
HTML_QuickForm_Renderer::renderHtml() -- Visit a raw HTML/text element (パッケージ開発者用)

既存のレンダラを拡張したり、新しいレンダラを書く場合には、以下が参考となるでしょう。