Form クラス
The Form class can both be used to create individual form elements or to create a full form along with
validation, the latter is done in combination with the Fieldset class.
Create individual form elements
open($attributes = array(), $hidden = array())
Create a form open tag.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$attributes |
array()
|
Either a string which will be the action attribute or an array of settings, if
action isn't given it will use the current Uri. The attribute's values will be used
as html tag properties. |
$hidden |
array()
|
An associative array of fieldnames and their values, will all be set as hidden
fields. |
|
返り値 |
string |
例 |
// returns <form action="http://mydomain.com/uri/to/form" accept-charset="utf-8" method="post">
echo Form::open('uri/to/form');
// returns <form action="http://google.com/" accept-charset="utf-8" method="get">
echo Form::open(array('action' => 'http://google.com/', 'method' => 'get'));
|
close()
Create a form close tag.
Static |
Yes |
パラメータ |
(none) |
返り値 |
string |
例 |
// returns </form>
echo Form::close();
|
Creates an html input element. It can be set using the fieldname, its value and tag attributes or all
in one array as the first argument.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$field |
必須 |
Either a string for the fieldname or an array of tag attributes. |
$value |
null
|
Field value, will be ignored when the first param is an array. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::input('name', 'value', array('style' => 'border: 2px;'));
// more to be added
|
Creates an html button element. It can be set using the fieldname, its value and tag attributes or all
in one array as the first argument.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$field |
必須 |
Either a string for the fieldname or an array of tag attributes. |
$value |
null
|
Field value, will be ignored when the first param is an array. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::button('name', 'value', array('style' => 'border: 2px;'));
|
hidden($field, $value = null, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'hidden'.
password($field, $value = null, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'password'.
radio($field, $value = null, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'radio'.
For backwards compatibility this method also accepts: checkbox($field, $value = null, array $attributes = array())
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$field |
必須 |
Either a string for the fieldname or an array of tag attributes. |
$value |
null
|
Field value, will be ignored when the first param is an array. |
$checked |
null
|
Whether checked (if bool) or matches $value (if string), will be ignored when
the first param is an array. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::label('Male', 'gender');
echo Form::radio('gender', 'Male', true);
echo Form::label('Female', 'gender');
echo Form::radio('gender', 'Female');
|
checkbox($field, $value = null, $checked = null, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'checkbox'.
For backwards compatibility this method also accepts: checkbox($field, $value = null, array $attributes = array())
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$field |
必須 |
Either a string for the fieldname or an array of tag attributes. |
$value |
null
|
Field value, will be ignored when the first param is an array. |
$checked |
null
|
Whether checked (if bool) or matches $value (if string), will be ignored when
the first param is an array. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::label('Male', 'gender');
echo Form::checkbox('gender', 'Male', true);
echo Form::label('Female', 'gender');
echo Form::checkbox('gender', 'Female');
|
file($field, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'file'.
reset($field, $value = null, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'reset'.
submit($field, $value = null, $attributes = array())
This is an alias for Form::input() that automatically sets the type attribute to
'submit'.
textarea($field, $value = null, $attributes = array())
Creates an html textarea element. It can be set using the fieldname, its value and tag attributes or all
in one attribute for the first argument.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$field |
必須 |
Either a string for the fieldname or an array of tag attributes. |
$value |
null
|
Field value, will be ignored when the first param is an array. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::textarea('description', 'enter here', array('rows' => 6, 'cols' => 8));
// more to be added
|
select($field, $values = null, $options = array(), $attributes = array())
Creates an html select element. It can be set using the fieldname, its selected value(s), its options
and tag attributes or all in one attribute for the first argument.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$field |
必須 |
Either a string for the fieldname or an array of tag attributes. |
$values |
null
|
Selected value or array of values for multiselect, will be ignored when the first
param is an array. |
$options |
array()
|
Associative array of value=>label pairs, may also contain option groups as
opt_name=>array() where the array contains its set of value=>label pairs. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::select('country', 'none', array(
'none' => 'None',
'europe' => array(
'uk' => 'United Kingdom',
'nl' => 'Netherlands'
),
'us' => 'United States'
));
// more to be added
|
label($label, $id = null, $attributes = array())
Creates an html label element. It can be set using label, the id it's for and tag attributes or all
in one attribute for the first argument.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$label |
必須 |
Either a string for the label or an array of tag attributes. |
$id |
null
|
The field's id this label belongs to. |
$attributes |
array()
|
These will be used as html tag properties. |
|
返り値 |
string |
例 |
echo Form::label('Username', 'username');
// more to be added
|
fieldset_open($attributes = array(), $legend = null)
Create a fieldset open tag.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$attributes |
array()
|
An array of settings; may use the key of 'legend' to set the fieldset's legend attribute.
The attribute's values will be used as html tag properties. |
$legend |
string
|
String to be used for the legend fieldset option |
|
返り値 |
string |
例 |
// returns <fieldset >
echo Form::fieldset_open();
// returns <fieldset class="example-class" id="example-id">
echo Form::fieldset_open(array('class' => 'example-class', 'id' => 'example-id'));
// returns <fieldset class="example-class" id="example-id"><legend>Custom Legend</legend>
echo Form::fieldset_open(array('class' => 'example-class', 'id' => 'example-id'), 'Custom Legend');
// returns <fieldset class="example-class" id="example-id"><legend>Custom Legend</legend>
echo Form::fieldset_open(array('class' => 'example-class', 'id' => 'example-id', 'legend' => 'Custom Legend'));
|
fieldset_close()
Create a fieldset close tag.
Static |
Yes |
パラメータ |
(none) |
返り値 |
string |
例 |
// returns </fieldset>
echo Form::fieldset_close();
|
See Fieldset