Cakephp-form-handling
CakePHP-フォーム処理
CakePHPは、HTMLフォームを簡単かつ安全に処理するためのさまざまな組み込みタグを提供します。 他の多くのPHPフレームワークと同様に、HTMLの主要な要素もCakePHPを使用して生成されます。 以下は、HTML要素を生成するために使用されるさまざまな関数です。
次の関数は、選択オプションを生成するために使用されます。
Syntax | selectOptions( array _$elements array(), array $parents array(), boolean $showParents null, array $attributes array() ) |
Parameters |
|
Returns | array |
Description | Returns an array of formatted OPTION/OPTGROUP elements |
次の関数は* HTML select要素を生成するために使用されます*。
Syntax | select( string $fieldName, array $options array(), array $attributes array() ) |
Parameters |
Name attribute of the SELECT SELECT要素で使用されるOPTION要素の配列(「値」⇒「テキスト」のペアとして) select要素のHTML属性。 |
Returns | Formatted SELECT element |
Description | Returns a formatted SELECT element |
次の関数は、HTMLページでボタンを生成するために使用されます*。
Syntax | Button (string $title, array $options array() ) |
Parameters |
|
Returns | HTML button tag. |
Description | Creates a* <button> tag. The type attribute defaults to type="submit*". You can change it to a different value by using $options['type']. |
以下の関数は、HTMLページでチェックボックスを生成するために使用されます*。
Syntax | Checkbox (string $fieldName, array $options array() ) |
Parameters |
|
Returns | An HTML text input element. |
Description | Creates a checkbox input widget. |
次の関数は、HTMLページでフォームを作成するために使用されます。
Syntax | create( mixed $model null, array $options array() ) |
Parameters |
|
Returns | A formatted opening FORM tag. |
Description | Returns an HTML FORM element. |
次の関数は、HTMLページでファイルのアップロード機能を提供するために使用されます。
Syntax | file(string $fieldName, array $options array() ) |
Parameters |
|
Returns | A generated file input. |
Description | Creates file input widget. |
次の関数は、HTMLページに hidden element を作成するために使用されます。
Syntax | hidden( string $fieldName, array $options array() ) |
Parameters |
|
Returns | A generated hidden input |
Description | Creates a hidden input field |
次の関数は、HTMLページで* input要素*を生成するために使用されます。
Syntax | Input (string $fieldName, array $options array() ) |
Parameters |
|
Returns | Completed form widget |
Description | Generates a form input element complete with label and wrapper div |
次の関数は、HTMLページで*ラジオボタン*を生成するために使用されます。
Syntax | Radio (string $fieldName, array $options array(), array $attributesarray() ) |
Parameters |
|
Returns | Completed radio widget set |
Description | Creates a set of radio widgets. Will create a legend and fieldset by default. Use $options to control this. |
次の関数は、HTMLページで submit ボタンを生成するために使用されます。
Syntax | Submit (string $caption null, array $options array() ) |
Parameters |
|
Returns | An HTML submit button |
Description | Creates a submit button element. This method will generate <input/> elements that can be used to submit, and reset forms by using $options. Image submits can be created by supplying an image path for $caption. |
次の関数は、HTMLページでtextarea要素を生成するために使用されます*。
Syntax | Textarea (string $fieldName, array $options array() ) |
Parameters |
|
Returns | A generated HTML text input element |
Description | Creates a textarea widget |
例
次のコードに示すように、 config/routes.php ファイルに変更を加えます。
次のURLにアクセスして上記の例を実行します- http://localhost:85/CakePHP/register
出力
実行すると、次の出力が表示されます。