PHP 클래스 yii\widgets\ActiveForm

..
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\base\Widget
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$action array | string the form action URL. This parameter will be processed by [[\yii\helpers\Url::to()]].
$ajaxDataType the type of data that you're expecting back from the server.
$ajaxParam the name of the GET parameter indicating the validation request is an AJAX request.
$attributes the client validation options for individual attributes. Each element of the array represents the validation options for a particular attribute.
$enableAjaxValidation whether to enable AJAX-based data validation. If [[ActiveField::enableAjaxValidation]] is set, its value will take precedence for that input field.
$enableClientScript whether to hook up yii.activeForm JavaScript plugin. This property must be set true if you want to support client validation and/or AJAX validation, or if you want to take advantage of the yii.activeForm plugin. When this is false, the form will not generate any JavaScript.
$enableClientValidation whether to enable client-side data validation. If [[ActiveField::enableClientValidation]] is set, its value will take precedence for that input field.
$encodeErrorSummary whether to perform encoding on the error summary.
$errorCssClass the CSS class that is added to a field container when the associated attribute has validation error.
$errorSummaryCssClass the default CSS class for the error summary container.
$fieldClass the default field class name when calling ActiveForm::field to create a new field.
$fieldConfig the default configuration used by ActiveForm::field when creating a new field object. This can be either a configuration array or an anonymous function returning a configuration array. If the latter, the signature should be as follows: php function ($model, $attribute) The value of this property will be merged recursively with the $options parameter passed to ActiveForm::field.
$method the form submission method. This should be either post or get. Defaults to post. When you set this to get you may see the url parameters repeated on each request. This is because the default value of [[action]] is set to be the current request url and each submit will add new parameters instead of replacing existing ones. You may set [[action]] explicitly to avoid this: php $form = ActiveForm::begin([ 'method' => 'get', 'action' => ['controller/action'], ]);
$options the HTML attributes (name-value pairs) for the form tag.
$requiredCssClass the CSS class that is added to a field container when the associated attribute is required.
$scrollToError whether to scroll to the first error after validation.
$scrollToErrorOffset offset in pixels that should be added when scrolling to the first error.
$successCssClass the CSS class that is added to a field container when the associated attribute is successfully validated.
$validateOnBlur whether to perform validation when an input field loses focus. If [[ActiveField::$validateOnBlur]] is set, its value will take precedence for that input field.
$validateOnChange whether to perform validation when the value of an input field is changed. If [[ActiveField::validateOnChange]] is set, its value will take precedence for that input field.
$validateOnSubmit whether to perform validation when the form is submitted.
$validateOnType whether to perform validation while the user is typing in an input field. If [[ActiveField::validateOnType]] is set, its value will take precedence for that input field.
$validatingCssClass the CSS class that is added to a field container when the associated attribute is being validated.
$validationDelay number of milliseconds that the validation should be delayed when the user types in the field and [[validateOnType]] is set true. If [[ActiveField::validationDelay]] is set, its value will take precedence for that input field.
$validationUrl the URL for performing AJAX-based validation. This property will be processed by [[Url::to()]]. Please refer to [[Url::to()]] for more details on how to configure this property. If this property is not set, it will take the value of the form's action attribute.

공개 메소드들

메소드 설명
beginField ( Model $model, string $attribute, array $options = [] ) : string Begins a form field.
endField ( ) : string Ends a form field.
errorSummary ( Model | Model[] $models, array $options = [] ) : string Generates a summary of the validation errors.
field ( Model $model, string $attribute, array $options = [] ) : ActiveField Generates a form field.
init ( ) Initializes the widget.
run ( ) Runs the widget.
validate ( Model $model, mixed $attributes = null ) : array Validates one or several models and returns an error message array indexed by the attribute IDs.
validateMultiple ( array $models, mixed $attributes = null ) : array Validates an array of model instances and returns an error message array indexed by the attribute IDs.

보호된 메소드들

메소드 설명
getClientOptions ( ) : array Returns the options for the form JS widget.

메소드 상세

beginField() 공개 메소드

This method will create a new form field and returns its opening tag. You should call ActiveForm::endField afterwards.
또한 보기: endField()
또한 보기: field()
public beginField ( Model $model, string $attribute, array $options = [] ) : string
$model yii\base\Model the data model.
$attribute string the attribute name or expression. See [[Html::getAttributeName()]] for the format about attribute expression.
$options array the additional configurations for the field object.
리턴 string the opening tag.

endField() 공개 메소드

This method will return the closing tag of an active form field started by ActiveForm::beginField.
public endField ( ) : string
리턴 string the closing tag of the form field.

errorSummary() 공개 메소드

If there is no validation error, an empty error summary markup will still be generated, but it will be hidden.
또한 보기: errorSummaryCssClass
public errorSummary ( Model | Model[] $models, array $options = [] ) : string
$models yii\base\Model | yii\base\Model[] the model(s) associated with this form.
$options array the tag options in terms of name-value pairs. The following options are specially handled: - `header`: string, the header HTML for the error summary. If not set, a default prompt string will be used. - `footer`: string, the footer HTML for the error summary. The rest of the options will be rendered as the attributes of the container tag. The values will be HTML-encoded using [[\yii\helpers\Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered.
리턴 string the generated error summary.

field() 공개 메소드

A form field is associated with a model and an attribute. It contains a label, an input and an error message and use them to interact with end users to collect their inputs for the attribute.
또한 보기: fieldConfig
public field ( Model $model, string $attribute, array $options = [] ) : ActiveField
$model yii\base\Model the data model.
$attribute string the attribute name or expression. See [[Html::getAttributeName()]] for the format about attribute expression.
$options array the additional configurations for the field object. These are properties of [[ActiveField]] or a subclass, depending on the value of [[fieldClass]].
리턴 ActiveField the created ActiveField object.

getClientOptions() 보호된 메소드

Returns the options for the form JS widget.
protected getClientOptions ( ) : array
리턴 array the options.

init() 공개 메소드

This renders the form open tag.
public init ( )

run() 공개 메소드

This registers the necessary JavaScript code and renders the form close tag.
public run ( )

validate() 공개 정적인 메소드

This is a helper method that simplifies the way of writing AJAX validation code. For example, you may use the following code in a controller action to respond to an AJAX validation request: php $model = new Post; $model->load(Yii::$app->request->post()); if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } ... respond to non-AJAX request ... To validate multiple models, simply pass each model as a parameter to this method, like the following: php ActiveForm::validate($model1, $model2, ...);
public static validate ( Model $model, mixed $attributes = null ) : array
$model yii\base\Model the model to be validated.
$attributes mixed list of attributes that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated. When this method is used to validate multiple models, this parameter will be interpreted as a model.
리턴 array the error message array indexed by the attribute IDs.

validateMultiple() 공개 정적인 메소드

This is a helper method that simplifies the way of writing AJAX validation code for tabular input. For example, you may use the following code in a controller action to respond to an AJAX validation request: php ... load $models ... if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validateMultiple($models); } ... respond to non-AJAX request ...
public static validateMultiple ( array $models, mixed $attributes = null ) : array
$models array an array of models to be validated.
$attributes mixed list of attributes that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated.
리턴 array the error message array indexed by the attribute IDs.

프로퍼티 상세

$action 공개적으로 프로퍼티

the form action URL. This parameter will be processed by [[\yii\helpers\Url::to()]].
또한 보기: method for specifying the HTTP method for this form.
public array|string $action
리턴 array | string

$ajaxDataType 공개적으로 프로퍼티

the type of data that you're expecting back from the server.
public $ajaxDataType

$ajaxParam 공개적으로 프로퍼티

the name of the GET parameter indicating the validation request is an AJAX request.
public $ajaxParam

$attributes 공개적으로 프로퍼티

the client validation options for individual attributes. Each element of the array represents the validation options for a particular attribute.
public $attributes

$enableAjaxValidation 공개적으로 프로퍼티

whether to enable AJAX-based data validation. If [[ActiveField::enableAjaxValidation]] is set, its value will take precedence for that input field.
public $enableAjaxValidation

$enableClientScript 공개적으로 프로퍼티

whether to hook up yii.activeForm JavaScript plugin. This property must be set true if you want to support client validation and/or AJAX validation, or if you want to take advantage of the yii.activeForm plugin. When this is false, the form will not generate any JavaScript.
public $enableClientScript

$enableClientValidation 공개적으로 프로퍼티

whether to enable client-side data validation. If [[ActiveField::enableClientValidation]] is set, its value will take precedence for that input field.
public $enableClientValidation

$encodeErrorSummary 공개적으로 프로퍼티

whether to perform encoding on the error summary.
public $encodeErrorSummary

$errorCssClass 공개적으로 프로퍼티

the CSS class that is added to a field container when the associated attribute has validation error.
public $errorCssClass

$errorSummaryCssClass 공개적으로 프로퍼티

the default CSS class for the error summary container.
또한 보기: errorSummary()
public $errorSummaryCssClass

$fieldClass 공개적으로 프로퍼티

the default field class name when calling ActiveForm::field to create a new field.
또한 보기: fieldConfig
public $fieldClass

$fieldConfig 공개적으로 프로퍼티

the default configuration used by ActiveForm::field when creating a new field object. This can be either a configuration array or an anonymous function returning a configuration array. If the latter, the signature should be as follows: php function ($model, $attribute) The value of this property will be merged recursively with the $options parameter passed to ActiveForm::field.
또한 보기: fieldClass
public $fieldConfig

$method 공개적으로 프로퍼티

the form submission method. This should be either post or get. Defaults to post. When you set this to get you may see the url parameters repeated on each request. This is because the default value of [[action]] is set to be the current request url and each submit will add new parameters instead of replacing existing ones. You may set [[action]] explicitly to avoid this: php $form = ActiveForm::begin([ 'method' => 'get', 'action' => ['controller/action'], ]);
public $method

$options 공개적으로 프로퍼티

the HTML attributes (name-value pairs) for the form tag.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $options

$requiredCssClass 공개적으로 프로퍼티

the CSS class that is added to a field container when the associated attribute is required.
public $requiredCssClass

$scrollToError 공개적으로 프로퍼티

whether to scroll to the first error after validation.
부터: 2.0.6
public $scrollToError

$scrollToErrorOffset 공개적으로 프로퍼티

offset in pixels that should be added when scrolling to the first error.
부터: 2.0.11
public $scrollToErrorOffset

$successCssClass 공개적으로 프로퍼티

the CSS class that is added to a field container when the associated attribute is successfully validated.
public $successCssClass

$validateOnBlur 공개적으로 프로퍼티

whether to perform validation when an input field loses focus. If [[ActiveField::$validateOnBlur]] is set, its value will take precedence for that input field.
public $validateOnBlur

$validateOnChange 공개적으로 프로퍼티

whether to perform validation when the value of an input field is changed. If [[ActiveField::validateOnChange]] is set, its value will take precedence for that input field.
public $validateOnChange

$validateOnSubmit 공개적으로 프로퍼티

whether to perform validation when the form is submitted.
public $validateOnSubmit

$validateOnType 공개적으로 프로퍼티

whether to perform validation while the user is typing in an input field. If [[ActiveField::validateOnType]] is set, its value will take precedence for that input field.
또한 보기: validationDelay
public $validateOnType

$validatingCssClass 공개적으로 프로퍼티

the CSS class that is added to a field container when the associated attribute is being validated.
public $validatingCssClass

$validationDelay 공개적으로 프로퍼티

number of milliseconds that the validation should be delayed when the user types in the field and [[validateOnType]] is set true. If [[ActiveField::validationDelay]] is set, its value will take precedence for that input field.
public $validationDelay

$validationUrl 공개적으로 프로퍼티

the URL for performing AJAX-based validation. This property will be processed by [[Url::to()]]. Please refer to [[Url::to()]] for more details on how to configure this property. If this property is not set, it will take the value of the form's action attribute.
public $validationUrl