实例:

 <?php

            $form = ActiveForm::begin([
'fieldConfig' => [
'template' => '<div class="col-lg-3 control-label color666 fontweight">{label}:</div>
<div class="col-lg-5" style="padding-left: 15px;padding-right: 15px;">{input}</div>
<div class="col-lg-4">{error}</div>',
'inputOptions' => ['class' => 'form-control'],
],
'options' => ['class' => 'form-horizontal t-margin20','id'=>'form1','enctype'=>"multipart/form-data"],
]);
//\app\helpers\Util::dump($form);
/*打印此处$form ActiveForm::begin([]) 追踪源码,调用父级的widget的begin方法是实例化ActiveForm This method creates an instance of the calling class
*/
?>
/*
自定义样式
$form->field()
调用该方法 查看源码 注释写的 options配置是 ActiveField These are properties of [[ActiveField]] 查看 ActiveField 的属性 就知道可以修改哪些样式
/**
* Generates a form 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.
* @param Model $model the data model
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* about attribute expression.
* @param array $options the additional configurations for the field object. These are properties of [[ActiveField]]
* or a subclass, depending on the value of [[fieldClass]].
* @return ActiveField the created ActiveField object
* @see fieldConfig
*/
public function field($model, $attribute, $options = [])
{
$config = $this->fieldConfig;
if ($config instanceof \Closure) {
$config = call_user_func($config, $model, $attribute);
}
if (!isset($config['class'])) {
$config['class'] = $this->fieldClass;
}
return Yii::createObject(ArrayHelper::merge($config, $options, [
'model' => $model,
'attribute' => $attribute,
'form' => $this,
]));
}
*/ <?=$form->field($model, 'product_name',['labelOptions' => ['class' => 't-r-pd5'],'options'=>['class'=>'']])->textInput()?>
ActiveField 部分代码:
 <?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/ namespace yii\widgets; use Yii;
use yii\base\Component;
use yii\base\ErrorHandler;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\base\Model;
use yii\web\JsExpression; /**
* ActiveField represents a form input field within an [[ActiveForm]].
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ActiveField extends Component
{
/**
* @var ActiveForm the form that this field is associated with.
*/
public $form;
/**
* @var Model the data model that this field is associated with
*/
public $model;
/**
* @var string the model attribute that this field is associated with
*/
public $attribute;
/**
* @var array the HTML attributes (name-value pairs) for the field container tag.
* The values will be HTML-encoded using [[Html::encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* The following special options are recognized:
*
* - tag: the tag name of the container element. Defaults to "div".
*
* If you set a custom `id` for the container element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = ['class' => 'form-group'];
/**
* @var string the template that is used to arrange the label, the input field, the error message and the hint text.
* The following tokens will be replaced when [[render()]] is called: `{label}`, `{input}`, `{error}` and `{hint}`.
*/
public $template = "{label}\n{input}\n{hint}\n{error}";
/**
* @var array the default options for the input tags. The parameter passed to individual input methods
* (e.g. [[textInput()]]) will be merged with this property when rendering the input tag.
*
* If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $inputOptions = ['class' => 'form-control'];
/**
* @var array the default options for the error tags. The parameter passed to [[error()]] will be
* merged with this property when rendering the error tag.
* The following special options are recognized:
*
* - tag: the tag name of the container element. Defaults to "div".
* - encode: whether to encode the error output. Defaults to true.
*
* If you set a custom `id` for the error element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $errorOptions = ['class' => 'help-block'];
/**
* @var array the default options for the label tags. The parameter passed to [[label()]] will be
* merged with this property when rendering the label tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $labelOptions = ['class' => 'control-label'];
/**
* @var array the default options for the hint tags. The parameter passed to [[hint()]] will be
* merged with this property when rendering the hint tag.
* The following special options are recognized:
*
* - tag: the tag name of the container element. Defaults to "div".
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $hintOptions = ['class' => 'hint-block'];
/**
* @var boolean whether to enable client-side data validation.
* If not set, it will take the value of [[ActiveForm::enableClientValidation]].
*/
public $enableClientValidation;
/**
* @var boolean whether to enable AJAX-based data validation.
* If not set, it will take the value of [[ActiveForm::enableAjaxValidation]].
*/
public $enableAjaxValidation;
/**
* @var boolean whether to perform validation when the value of the input field is changed.
* If not set, it will take the value of [[ActiveForm::validateOnChange]].
*/
public $validateOnChange;
/**
* @var boolean whether to perform validation when the input field loses focus.
* If not set, it will take the value of [[ActiveForm::validateOnBlur]].
*/
public $validateOnBlur;
/**
* @var boolean whether to perform validation while the user is typing in the input field.
* If not set, it will take the value of [[ActiveForm::validateOnType]].
* @see validationDelay
*/
public $validateOnType;
/**
* @var integer number of milliseconds that the validation should be delayed when the user types in the field
* and [[validateOnType]] is set true.
* If not set, it will take the value of [[ActiveForm::validationDelay]].
*/
public $validationDelay;
/**
* @var array the jQuery selectors for selecting the container, input and error tags.
* The array keys should be "container", "input", and/or "error", and the array values
* are the corresponding selectors. For example, `['input' => '#my-input']`.
*
* The container selector is used under the context of the form, while the input and the error
* selectors are used under the context of the container.
*
* You normally do not need to set this property as the default selectors should work well for most cases.
*/
public $selectors = [];
/**
* @var array different parts of the field (e.g. input, label). This will be used together with
* [[template]] to generate the final field HTML code. The keys are the token names in [[template]],
* while the values are the corresponding HTML code. Valid tokens include `{input}`, `{label}` and `{error}`.
* Note that you normally don't need to access this property directly as
* it is maintained by various methods of this class.
*/
public $parts = [];

Yii2 ActiveForm表单自定义样式的更多相关文章

  1. [moka同学笔记]yii2 activeForm 表单样式的修改(二)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABAEAAANXCAIAAADLkdErAAAgAElEQVR4nOzdfWwc953nef6zwO5Zg8

  2. [moka同学笔记]yii2 activeForm 表单样式的修改

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAv4AAANcCAIAAACopDy/AAAgAElEQVR4nOzdfXAb52H4ef1veSatRV

  3. [YII2] Activeform表单部分组件使用方法

    文本框:textInput(); 密码框:passwordInput(); 单选框:radio(),radioList(); 复选框:checkbox(),checkboxList(); 下拉框:dr ...

  4. yii中调整ActiveForm表单样式

    Yii2中对于表单和字段的支持组件为ActiveForm和ActiveField, <?php $form = ActiveForm::begin([ 'id' => 'login-for ...

  5. yii2 创建ActiveForm(表单)

    表单的生成表单中的方法    ActiveForm::begin()方法    ActiveForm::end()方法    getClientOptions()方法    其它方法:errorSum ...

  6. YII2.0使用ActiveForm表单(转)

    Controller控制器层代码 <?php namespace frontend\controllers; use frontend\models\UserForm; class UserCo ...

  7. yii2之ActiveForm表单使用

    因目前项目并非前后端分离模式,且用到PHP的yii2框架(所有html代码,js较多内嵌在.php文件内多少采用同步提交[喷墨中...]),遂对于前端面上需要用到的yii2小组件一些整理(因是前端若涉 ...

  8. css修改input表单默认样式重置与自定义大全

    链接地址: 伪元素表单控件默认样式重置与自定义大全 http://www.zhangxinxu.com/wordpress/?p=3381 Chrome 现在不支持通过伪元素修改 meter 元素样式 ...

  9. [moka同学笔记]yii2.0表单的使用

    1.创建model   /biaodan.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/08/05 * Tim ...

随机推荐

  1. js事件对象--DOM中的事件对象/IE中的事件对象/跨浏览器的事件对象

    事件对象    在触发DOM上的某个事件时,会产生一个事件对象event,这个对象中包含着所有与事件有关的信息.包括导致事件的元素.事件的类型,以及其他与特定事件相关的信息.例如,鼠标操作导致的事件对 ...

  2. 玩转HTML5移动页面(优化篇)

    原文:http://www.grycheng.com/?p=472 承接上文<玩转HTML5移动页面(动效篇)>,上次说的是让页面动起来的一些小技巧.而页面动起来的根基是功能可用的页面,因 ...

  3. 开源搜索引擎Sphinx 中启动多个搜索进程的方法

    http://blog.163.com/yang_jianli/blog/static/1619900062010316504471/ 要在同一机器上启动多个sphinx搜索进程searchd,必须为 ...

  4. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  5. zzuli oj 1165 实数的小数部分(指针专题)

    Description 读入一个实数,输出该实数的小数部分,小数部分若多余的末尾0,请去掉.如输入111111.12345678912345678900  则输出0.12345678912345678 ...

  6. MVC页面上多个提交按钮提交到不同的Action

    使用mvc扩展类,ActionNameAttribute方法如下: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, In ...

  7. MINA源码分析

    IoService通过构造函数的形式成为了IoSession一部分,IoSession是通过IoAcceptor以及connector创建出来,这二者其实就是IoService,所以对于IoSessi ...

  8. BZOJ3190[JLOI2013]赛车

    Description 这里有一辆赛车比赛正在进行,赛场上一共有N辆车,分别称为个g1,g2--gn.赛道是一条无限长的直线.最初,gi位于距离起跑线前进ki的位置.比赛开始后,车辆gi将会以vi单位 ...

  9. 第 14 章 迭代器模式【Iterator Pattern】

    以下内容出自:<<24种设计模式介绍与6大设计原则>> 周五下午,我正在看技术网站,第六感官发觉有人在身后,扭头一看,我C,老大站在背后,赶忙站起来, “王经理,你找我?” 我 ...

  10. Django关于filter和get()方法

    首先引入一个问题: 问: card = Card.objects.filter(pk=offline_card_id).get() card = Card.objects.get(pk=offline ...