选择语言 :

Core_Form

表单核心类

API - Core_Form

author
呼吸二氧化碳 jonwang@myqee.com
category
MyQEE
package
System
subpackage
Core
copyright
Copyright © 2008-2013 myqee.com
license
http://www.myqee.com/license.html

Form::open( $action = null, $attributes = null, $add_token = true)

创建一个表单

$add_token 参数为是否创建一个token验证隐藏表单,用于预防 CSRF 攻击

$add_token 功能适用于动态页面,而不能应用于有可能被缓存或HTML静态化的页面
// Form will submit back to the current page using POST
echo Form::open();

// Form will submit to 'search' using GET
echo Form::open('search', array('method' => 'get'));

// When "file" inputs are present, you must include the "enctype"
echo Form::open(null, array('enctype' => 'multipart/form-data'));

参数列表

参数 类型 描述 默认值
$action string Form action, defaults to the current request URI null
$attributes array Html attributes null
$add_token boolean 是否添加token验证功能 bool true
返回值
  • string

Form::close( )

Creates the closing form tag.

echo Form::close();
返回值
  • string

Form::input( $name , $value = null, $attributes = null)

Creates a form input. If no type is specified, a "text" type input will be returned.

echo Form::input('username', $username);

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value null
$attributes array Html attributes null
返回值
  • string

Form::hidden( $name , $value = null, $attributes = null)

Creates a hidden form input.

echo Form::hidden('csrf', $token);

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value null
$attributes array Html attributes null
返回值
  • string

Form::password( $name , $value = null, $attributes = null)

Creates a password form input.

echo Form::password('password');

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value null
$attributes array Html attributes null
返回值
  • string

Form::file( $name , $attributes = null)

Creates a file upload form input. No input value can be specified.

echo Form::file('image');

参数列表

参数 类型 描述 默认值
$name string Input name
$attributes array Html attributes null
返回值
  • string

Form::checkbox( $name , $value = null, $checked = false, $attributes = null)

Creates a checkbox form input.

echo Form::checkbox('remember_me', 1, (bool) $remember);

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value null
$checked boolean Checked status bool false
$attributes array Html attributes null
返回值
  • string

Form::radio( $name , $value = null, $checked = false, $attributes = null)

Creates a radio form input.

echo Form::radio('like_cats', 1, $cats);
echo Form::radio('like_cats', 0, !$cats);

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value null
$checked boolean Checked status bool false
$attributes array Html attributes null
返回值
  • string

Form::textarea( $name , $body = '', $attributes = null, $double_encode = false)

Creates a textarea form input.

echo Form::textarea('about', $about);

参数列表

参数 类型 描述 默认值
$name string Textarea name
$body string Textarea body empty
$attributes array Html attributes null
$double_encode boolean Encode existing HTML characters bool false
返回值
  • string

Form::select( $name , $options = null, $selected = null, $attributes = null)

Creates a select form input.

echo Form::select('country', $countries, $country);

参数列表

参数 类型 描述 默认值
$name string Input name
$options array Available options null
$selected mixed Selected option string, or an array of selected options null
$attributes array Html attributes null
返回值
  • string

Form::submit( $name , $value , $attributes = null)

Creates a submit form input.

 echo Form::submit(null, 'Login');

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value
$attributes array Html attributes null
返回值
  • string

Form::image( $name , $value , $attributes = null)

Creates a image form input.

echo Form::image(null, null, array('src' => 'media/img/login.png'));

参数列表

参数 类型 描述 默认值
$name string Input name
$value string Input value
$attributes array Html attributes null
返回值
  • string

Form::button( $name , $body , $attributes = null)

Creates a button form input. Note that the body of a button is NOT escaped, to allow images and other HTML to be used.

echo Form::button('save', 'Save Profile', array('type' => 'submit'));

参数列表

参数 类型 描述 默认值
$name string Input name
$body string Input value
$attributes array Html attributes null
返回值
  • string

Form::label( $input , $text = null, $attributes = null)

Creates a form label. Label text is not automatically translated.

echo Form::label('username', 'Username');

参数列表

参数 类型 描述 默认值
$input string Target input
$text string Label text null
$attributes array Html attributes null
返回值
  • string

Form::get_token( )

获取一个token的数据数组

返回值
  • array

Form::check_token( )

校验表单token

当使用 Form::open() 方法开启 token 后,可试用此方法在接受页面中校验token是否正确

返回值
  • bool

Form::delete_token( )

删除相关token,避免被重复利用

返回值
  • null

Form::get_token_hash( $str , $key )

根据一个字符串生成一个token hash

参数列表

参数 类型 描述 默认值
$str string $str
$key unknown
返回值
  • string