Home >PHP Framework >YII >How to write a yii framework form?
In Yii, forms (form widgets) are mainly created through the yii\widgets\ActiveForm class. Let's introduce how to write forms in yii. We hope it will be helpful to students who are learning the yii framework!
How to write a yii framework form?
(1) First create a form instance
<?php $form=ActiveForm::begin();?> //$form是表单实例 ... <?php ActiveForm::end();?>
ActiveForm::begin() not only marks the start of the form, but also creates a form instance.
Recommended learning: yii tutorial
(2) Then create an ActiveField instance
<?php $form=ActiveForm::begin();?> + <?= $form->field($model,'title')?> <?php ActiveForm::end();?>
and place it in ActiveForm: Everything between :begin() and ActiveForm::end() is wrapped in the HTML ff9c23ada1bcecdd1a0fb5d5a0f18437 tag.
Create an ActiveField instance by calling the ActiveForm::field() method. This instance will create the form element and the element's label, as well as the corresponding JavaScript response.
Each ActiveField has a corresponding model and attribute. The name attribute of the input input box will be automatically created based on the attribute name; at the same time, the attribute verification rules will be used to verify the user's data input.
(3) Create an ActiveField object using the example
<?= $form->field($model,'body')->textarea(['rows'=>3]) =?>
$form->field($model,'body');
ActiveField's method textarea() creates a 3-line input box;
The above is the detailed content of How to write a yii framework form?. For more information, please follow other related articles on the PHP Chinese website!