form in Yii framework
Students who have used the yii framework all know that the form form in the yii framework can be submitted using the yii internally defined form component. The editor today Let's take a look at the formform component in yii!
Without further ado, let’s talk about the code:
<?php //引入命名空间 use yii\helpers\Html; ?> <?php //表单:Html::beginForm(提交地址,提交方法,属性数组);?> $form = ActiveForm::begin([ 'action' => ['test/getpost'], 'method'=>'post', ]); ?> <?=Html::beginForm('','post',['id'=>'form','class'=>'form','data'=>'myself']);?> <?php //(二)输入框:Html::input(类型,name值,默认值,属性数组;)?> <?=Html::input('text','test','',['class'=>'form-control','placeholder'=>'hehe'])->hint('Please enter your test')->label('Name');?> <?=Html::input('email','email','admin@admin.com',['class'=>'form-control']);?> <?=Html::input('password','pwd','',['class'=>'form-control']);?> <?Html::input('hidden','hidden','',['class'=>'form-control']);?> <hr/> <?php //Html::表单类型input(name值,默认值,属性数值);?> <?=Html::textInput('test','hehe',['class'=>'form-control']);?> <?=Html::textInput('email','admin@admin.com',['class'=>'form-control']);?> <?Html::passwordInput('pwd','',['class'=>'form-control']);?> <?Html::hiddenInput('hidden','',['class'=>'form-control']);?> <hr/> <?php //(三) 文本域 Html::textarea()?> <?=Html::textarea('area','',['class'=>'form-control','row'=>'3']);?> <hr/> <?php //单选按钮 Html::checkbox(name值,是否选中,属性数组)?> <?=Html::radio('sex',true,['class'=>'form-control']);?> <?=Html::radioList('height','1',['1'=>'160','2'=>'170','3'=>'180'],['class'=>'form-control']);?> <?php //复选框?> <?=Html::checkbox('haha',true,['class'=>'form-control']);?> <?php //复选框列表?> <?=Html::checkboxList('xixi','1',['1'=>'160','2'=>'170','3'=>'180'],['class'=>'form-control']);?> <?php //下拉列表?> <?=Html::dropDownList('list','2',['1'=>'160','2'=>'170','3'=>'180'],['class'=>'form-control'])?> <?=Html::label('显示的','test',['style'=>'color:#ff0000']);?> <hr/> <?php //上传控件?> <?=Html::fileInput('img',null,['class'=>'btn btn-default']);?> <hr/> <?php //按钮?> <?=Html::button('普通按钮',['class'=>'btn btn-primary']);?> <?=Html::submitButton('提交按钮',['class'=>'btn btn-primary']);?> <?=Html::resetButton('重置按钮',['class'=>'btn btn-primary']);?> <?=Html::endForm()?>
##Text box: textInput(); Password box :passwordInput();
Radio box:radio(),radioList();
Checkbox:checkbox(),checkboxList();
Dropdown box:dropDownList();
Hidden field :hiddenInput();
Text area: textarea(['rows'=>3]);
File upload:fileInput(); Submit button:submitButton();
Reset Button:resetButtun();
The following is a code example:
<?php $form = ActiveForm::begin(['action' => ['test/getpost'],'method'=>'post',]); ?> <? echo $form->field($model, 'username')->textInput(['maxlength' => 20]) ?> <? echo $form->field($model, 'password')->passwordInput(['maxlength' => 20]) ?> <? echo $form->field($model, 'sex')->radioList(['1'=>'男','0'=>'女']) ?> <? echo $form->field($model, 'edu')->dropDownList(['1'=>'大学','2'=>'高中','3'=>'初中'], ['prompt'=>'请选择','style'=>'width:120px']) ?> <? echo $form->field($model, 'file')->fileInput() ?> <? echo $form->field($model, 'hobby')->checkboxList(['0'=>'篮球','1'=>'足球','2'=>'羽毛球','3'=>'乒乓球']) ?> <? echo $form->field($model, 'info')->textarea(['rows'=>3]) ?> <? echo $form->field($model, 'userid')->hiddenInput(['value'=>3]) ?> <? echo Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?> <? echo Html::resetButton('重置', ['class'=>'btn btn-primary','name' =>'submit-button']) ?> <?php ActiveForm::end(); ?>
Related recommendations:
How to load the verification code function that comes with Yii
Detailed explanation of the method of leaving the current page after adding, deleting, modifying and checking in Yii2
Using Yii form model and submitting form data in array form_PHP tutorial
The above is the detailed content of form in Yii framework. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement page jump after PHP form submission [Introduction] In web development, form submission is a common functional requirement. After the user fills out the form and clicks the submit button, the form data usually needs to be sent to the server for processing, and the user is redirected to another page after processing. This article will introduce how to use PHP to implement page jump after form submission. [Step 1: HTML Form] First, we need to write a page containing a form in an HTML page so that users can fill in the data that needs to be submitted.

How to handle user rights management in PHP forms With the continuous development of web applications, user rights management is one of the important functions. User rights management can control users' operating rights in applications and ensure the security and legality of data. In PHP forms, user rights management can be implemented through some simple code. This article will introduce how to handle user rights management in PHP forms and give corresponding code examples. 1. Definition and management of user roles First of all, defining and managing user roles is a matter of user rights.

How to use JavaScript to implement real-time verification of the input box content of a form? In many web applications, forms are the most common way of interaction between users and the system. However, the content entered by the user often needs to be validated to ensure the accuracy and completeness of the data. In this article, we will learn how to use JavaScript to implement real-time verification of the content of the form's input box and provide specific code examples. Creating the form First we need to create a simple table in HTML

How to use JavaScript to realize the automatic prompt function of the input box content of the form? Introduction: The automatic prompt function of the form input box content is very common in web applications. It can help users quickly enter the correct content. This article will introduce how to use JavaScript to achieve this function and provide specific code examples. Create the HTML structure First, we need to create an HTML structure that contains the input box and the auto-suggestion list. You can use the following code: <!DOCTYP

PHP form processing: form data query and filtering Introduction In Web development, forms are an important way of interaction. Users can submit data to the server through forms for further processing. This article will introduce how to use PHP to process the query and filter functions of form data. Form design and submission First, we need to design a form that includes query and filter functions. Common form elements include input boxes, drop-down lists, radio buttons, check boxes, etc., which can be designed according to specific needs. When the user submits the form, the data will be sent to POS

How to use HTML, CSS and jQuery to implement the advanced function of automatic saving of forms. Forms are one of the most common elements in modern web applications. When users enter form data, how to implement the automatic saving function can not only improve the user experience, but also ensure data security. This article will introduce how to use HTML, CSS and jQuery to implement the automatic saving function of the form, and attach specific code examples. 1. Structure of HTML form. Let’s first create a simple HTML form.

Forms are an integral part of writing a website or application. Laravel, as a popular PHP framework, provides rich and powerful form classes, making form processing easier and more efficient. This article will introduce some tips on using Laravel form classes to help you improve development efficiency. The following explains in detail through specific code examples. Creating a form To create a form in Laravel, you first need to write the corresponding HTML form in the view. When working with forms, you can use Laravel

How to create a form with floating prompts using HTML, CSS and jQuery In modern web design, forms are one of the indispensable components. In order to improve user experience, we often need to add some floating prompts to the form to guide users to fill in the form correctly. This article will introduce how to use HTML, CSS and jQuery to create a form with floating prompts, and provide specific code examples. First, we need to create the HTML form. In the form we need to add some input fields, and
