本文整理汇总了PHP中kartik\form\ActiveForm类的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm类的具体用法?PHP ActiveForm怎么用?PHP ActiveForm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActiveForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isset
//index view
$viewId = Yii::$app->request->get('view_id');
if (!isset($viewId)) {
?>
<button type="button" class="btn btn-primary btn-lg" onclick="javascript: $('#address').toggle()">新建收货地址</button>
<?php
}
?>
<div id="address" style="display: <?php
echo isset($viewId) ? 'block' : 'none';
?>
">
<?php
$form = \kartik\form\ActiveForm::begin();
/* @var \yincart\customer\models\CustomerAddress $model */
echo $form->field($model, 'province')->dropDownList($catList, ['id' => 'cat-id']);
// Child # 1
echo $form->field($model, 'city')->widget(DepDrop::classname(), ['data' => [$model->city => isset($model->cityArea) ? $model->cityArea->name : ''], 'options' => ['id' => 'subcat-id'], 'pluginOptions' => ['depends' => ['cat-id'], 'placeholder' => 'Select...', 'url' => Url::to(['/customer/get-cities'])]]);
// Child # 2
echo $form->field($model, 'district')->widget(DepDrop::classname(), ['data' => [$model->district => isset($model->districtArea) ? $model->districtArea->name : ''], 'pluginOptions' => ['depends' => ['cat-id', 'subcat-id'], 'placeholder' => 'Select...', 'url' => Url::to(['/customer/get-district'])]]);
?>
<?php
echo $form->field($model, 'address')->textInput(['maxlength' => 255]);
?>
<?php
echo $form->field($model, 'zip_code')->textInput(['maxlength' => 255]);
?>
示例2:
<?
/**
* @var $model Registration
* @var $invoice Invoice
*/
use common\models\Registration;
use common\models\Invoice;
use kartik\form\ActiveForm;
use vova07\imperavi\Widget;
use kartik\helpers\Html;
?>
<?php
$form = ActiveForm::begin(['id' => 'credit-note-form', 'action' => Yii::$app->urlManager->createUrl(['/registration/create-credit-note/', 'code' => $model->code]), 'options' => ['target' => '_blank']]);
?>
<div class="row">
<div class="col-md-12">
<?php
echo $form->field($invoice, 'newAmount')->textInput();
?>
<?php
echo Html::label('Subject', 'Invoice[subject]');
?>
<?php
echo Widget::widget(['name' => 'Invoice[subject]', 'value' => $invoice->subject, 'settings' => ['minHeight' => 200, 'plugins' => ['clips']]]);
?>
示例3:
if ($mode == 'new') {
$this->title = 'Добавление новости';
$breadcrumb = $this->title;
}
$this->params['breadcrumbs'][] = ['url' => '/news', 'label' => 'Новости'];
$this->params['breadcrumbs'][] = $breadcrumb;
echo Html::beginTag('div', ['class' => 'col-xs-12']);
if (\Yii::$app->session->getFlash('saved', false)) {
echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('saved'), 'options' => ['class' => 'alert alert-success alert-dismissible']]);
} else {
if (\Yii::$app->session->getFlash('error', false)) {
echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('error'), 'options' => ['class' => 'alert alert-danger alert-dismissible row col-xs-10 col-xs-offset-1']]);
}
}
echo Html::endTag('div');
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL]);
?>
<div class="panel panel-default">
<div class="panel-heading">
<?php
echo $this->render('_news_header_buttons', ['model' => $model, 'mode' => $mode]);
?>
</div>
<div class="panel-body">
<?php
echo Html::tag('div', $form->field($model, 'title') . $form->field($model, 'category')->widget(\kartik\select2\Select2::className(), ['data' => ArrayHelper::map(Category::find()->where(['deleted' => 0])->asArray()->all(), 'id', 'title')]) . $form->field($model, 'link')->hint('Оставьте поле пустым, чтобы ссылку сгенерировала система') . $form->field($model, 'text')->widget(\yii\imperavi\Widget::className(), ['id' => 'textEditor', 'options' => ['lang' => 'ru', 'imageUpload' => '/news/upload', 'imageManagerJson' => '/news/uploaded'], 'plugins' => ['imagemanager', 'video', 'border']]) . $form->field($model, 'metaDescription')->textarea() . $form->field($model, 'metaKeywords') . $form->field($model, 'language')->dropDownList($model->getLanguages()) . $form->field($model, 'publishDate')->widget(\kartik\datetime\DateTimePicker::className(), ['pluginOptions' => ['format' => 'dd.mm.yyyy HH:ii']]) . $form->field($model, 'genre')->dropDownList($model->getGenres()) . $form->field($model, 'author'), ['class' => 'col-xs-12']), $form->field($model, 'published', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), $form->field($model, 'favorite', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), $form->field($model, 'deleted', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), $form->field($model, 'moderatedComments', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), Html::tag('div', Html::button(FontAwesome::i('save') . Html::tag('small', 'сохранить'), ['class' => 'btn btn-app btn-success', 'type' => 'submit']), ['class' => 'text-center']);
?>
</div>
</div>
<?php
$form->end();
示例4:
<?= $form->field($model, 'head_picture')->label(Yii::t('app', 'Upload Head Picture'))->widget(FileInput::classname(), [
'pluginOptions' => [
'uploadUrl' => Url::to(['/user/upload-head-pic']),
'uploadAsync' => false,
'allowedPreviewTypes' => ['image'],
'allowedFileExtensions' => ['png', 'jpg', 'jpeg'],
'maxFileCount' => 1,
'maxFileSize' => 1000,
'uploadExtraData' => [
'_csrf' => Yii::$app->request->csrfToken,
'User[id]' => $model->id,
]
]
]); ?>
<?php ActiveForm::end(); ?>
</div>
<div class="col-lg-2 col-lg-offset-5 col-md-2 col-md-offset-5 col-sm-2 col-sm-offset-2 profile-save">
<button class="btn btn-info" onclick="profileSave()" id="profile-save-btn"><span class="fa fa-spinner fa-pulse" style="display:none"></span>保存</button>
</div>
</div>
<!-- <div class="mengceng">
<span class="fa fa-refresh fa-spin fa-3x gif"></span>
</div> -->
<script type="text/javascript">
示例5: actionUpdate
/**
* @inheritdoc
* */
public function actionUpdate($id = null)
{
if ($id) {
$modelObject = $this->findRecordModel($id);
} else {
$modelObject = Yii::createObject($this->model);
}
/** @var \nagser\gallery\models\GalleryRecord $modelObject * */
if (\Yii::$app->request->isAjax) {
if ($modelObject->load(\Yii::$app->request->post())) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($modelObject);
} else {
return $this->renderAjax('update', ['model' => $modelObject]);
}
} else {
if (Yii::$app->request->isPost) {
$modelObject->file = Yii::$app->gallery->upload($modelObject);
if ($modelObject->upload() and $modelObject->scenario = 'save' and $modelObject->load(\Yii::$app->request->post()) and $modelObject->save()) {
$this->redirect(Url::to(['view', 'id' => $modelObject->id]));
}
}
return $this->render('update', ['model' => $modelObject]);
}
}
示例6: actionCopy
public function actionCopy($id)
{
$model = \Yii::createObject($this->model);
/** @var ThemesRecord $model **/
$model = $model->findRecordModel($id);
if (\Yii::$app->request->isAjax) {
if ($model->load(\Yii::$app->request->post())) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} else {
return $this->renderAjax('copy', ['model' => $model]);
}
} else {
if ($model->load(\Yii::$app->request->post())) {
$model->copy($id);
$this->redirect(Url::to(['view', 'id' => $model->dir]));
}
}
}
示例7:
?>
</h1>
<div class="cart">
<?php
if (!is_null($model) && $model->items_count > 0) {
?>
<?php
echo $this->render('items', ['model' => $model, 'items' => $model->items]);
?>
<div class="pull-right">
<div class="discount-code">
<?php
if ($orderCode->isNewRecord) {
?>
<?php
$form = \kartik\form\ActiveForm::begin(['type' => \kartik\form\ActiveForm::TYPE_INLINE]);
?>
<?php
echo $form->errorSummary($orderCode);
?>
<?php
echo $form->field($orderCode, 'code');
?>
<?php
echo \kartik\helpers\Html::submitButton(Yii::t('app', 'Apply code'), ['class' => 'btn btn-success']);
?>
<?php
echo \kartik\helpers\Html::endForm();
?>
<?php
} else {
示例8: renderRawActiveInput
/**
* Renders raw active input based on the attribute settings
*
* @param \kartik\form\ActiveForm $form the form instance
* @param \yii\db\ActiveRecord|\yii\base\Model $model
* @param string $attribute the name of the attribute
* @param array $settings the attribute settings
*
* @return \kartik\form\ActiveField
* @throws \yii\base\InvalidConfigException
*
*/
protected static function renderRawActiveInput($form, $model, $attribute, $settings)
{
$type = ArrayHelper::getValue($settings, 'type', self::INPUT_TEXT);
$i = strpos($attribute, ']');
$attribName = $i > 0 ? substr($attribute, $i + 1) : $attribute;
if (!in_array($type, static::$_validInputs)) {
throw new InvalidConfigException("Invalid input type '{$type}' configured for the attribute '{$attribName}'.'");
}
$fieldConfig = ArrayHelper::getValue($settings, 'fieldConfig', []);
$options = ArrayHelper::getValue($settings, 'options', []);
$label = ArrayHelper::getValue($settings, 'label', null);
$hint = ArrayHelper::getValue($settings, 'hint', null);
$field = $form->field($model, $attribute, $fieldConfig);
if ($type === self::INPUT_TEXT || $type === self::INPUT_PASSWORD || $type === self::INPUT_TEXTAREA || $type === self::INPUT_FILE || $type === self::INPUT_HIDDEN || $type === self::INPUT_STATIC) {
return static::getInput($field->{$type}($options), $label, $hint);
}
if ($type === self::INPUT_DROPDOWN_LIST || $type === self::INPUT_LIST_BOX || $type === self::INPUT_CHECKBOX_LIST || $type === self::INPUT_RADIO_LIST || $type === self::INPUT_MULTISELECT) {
if (!isset($settings['items'])) {
throw new InvalidConfigException("You must setup the 'items' array for attribute '{$attribName}' since it is a '{$type}'.");
}
return static::getInput($field->{$type}($settings['items'], $options), $label, $hint);
}
if ($type === self::INPUT_CHECKBOX || $type === self::INPUT_RADIO) {
$enclosedByLabel = ArrayHelper::getValue($settings, 'enclosedByLabel', true);
if ($label !== null) {
$options['label'] = $label;
}
return static::getInput($field->{$type}($options, $enclosedByLabel), null, $hint);
}
if ($type === self::INPUT_HTML5) {
$html5type = ArrayHelper::getValue($settings, 'html5type', 'text');
return static::getInput($field->{$type}($html5type, $options), $label, $hint);
}
if ($type === self::INPUT_WIDGET) {
$widgetClass = ArrayHelper::getValue($settings, 'widgetClass', []);
if (empty($widgetClass) && !$widgetClass instanceof yii\widgets\InputWidget) {
throw new InvalidConfigException("A valid 'widgetClass' for '{$attribute}' must be setup and extend from 'yii\\widgets\\InputWidget'.");
}
return static::getInput($field->{$type}($widgetClass, $options), $label, $hint);
}
if ($type === self::INPUT_RAW) {
return ArrayHelper::getValue($settings, 'value', '');
}
}
示例9:
}
?>
<?php
echo Html::a(Icon::show('arrow-circle-left') . Yii::t('app', 'Back'), Yii::$app->request->get('returnUrl', ['/review/backend/index']), ['class' => 'btn btn-default']);
?>
<?php
echo Html::submitButton(Icon::show('save') . Yii::t('app', 'Save'), ['class' => 'btn btn-primary', 'name' => 'action', 'value' => 'save']);
?>
</div>
</div>
<?php
$this->endBlock('submit');
?>
<?php
$form = ActiveForm::begin(['id' => 'product-form', 'type' => ActiveForm::TYPE_HORIZONTAL, 'options' => ['enctype' => 'multipart/form-data']]);
?>
<div class="review-show">
<?php
if (false === $review->isNewRecord) {
?>
<div class="row">
<article class="col-xs-12 col-sm-6 col-md-6 col-lg-6"></article>
<article class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<?php
echo \app\properties\PropertiesWidget::widget(['model' => $submission, 'form' => $form]);
?>
</article>
</div>
<?php
}
示例10: actionCreate
/**
* Create a new User model. If creation is successful, the browser will
* be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
/** @var \amnah\yii2\user\models\User $user */
/** @var \amnah\yii2\user\models\Profile $profile */
/** @var \amnah\yii2\user\models\Role $role */
// AuthAssigment
$permissoes = AuthItem::getListToDropDownList();
$permissoesUser = null;
// set up new user/profile objects
$user = $this->module->model("User", ["scenario" => "register"]);
$profile = $this->module->model("Profile");
$mensagem = "";
//Informa ao usuário mensagens de erro na view
//Permissão do usuário
$authAssignment = new AuthAssignment();
$user->status = 1;
// load post data
$post = Yii::$app->request->post();
if ($user->load($post)) {
// ensure profile data gets loaded
$profile->load($post);
//Inicia a transação:
$transaction = \Yii::$app->db->beginTransaction();
try {
// validate for ajax request
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($user, $profile);
}
// validate for normal request
if ($user->validate() && $profile->validate()) {
$itensInseridos = true;
// perform registration
$role = $this->module->model("Role");
if (!$user->setRegisterAttributes($role::ROLE_USER, $user::STATUS_ACTIVE)->save()) {
$mensagem = "Não foi possível salvar os dados";
$transaction->rollBack();
//desfaz alterações no BD
$itensInseridos = false;
}
if (!$profile->setUser($user->id)->save()) {
$mensagem = "Não foi possível salvar os dados";
$transaction->rollBack();
//desfaz alterações no BD
$itensInseridos = false;
}
$idUser = $user->id;
if (isset($post['AuthAssignment']['item_name']) && !empty($post['AuthAssignment']['item_name'])) {
//Guarda as permissões escolhidas
$roles = $post['AuthAssignment']['item_name'];
foreach ($roles as $role) {
$user->setPermissoes($role, $idUser);
}
}
if ($itensInseridos) {
$transaction->commit();
return $this->redirect(['view', 'id' => $user->id]);
}
}
} catch (\Exception $exception) {
$transaction->rollBack();
$mensagem = "Ocorreu uma falha inesperada ao tentar salvar";
}
}
return $this->render("create", compact("user", "profile", "permissoes", "permissoesUser", "mensagem", "authAssignment"));
}
示例11:
<li class="list-group-item list-group-item-current"><?php
echo Yii::t('setup', 'Create admin account');
?>
</li>
<li class="list-group-item"><?php
echo Yii::t('setup', 'Finished');
?>
</li>
</ul>
</div>
<div class="col-sm-8 form-wrapper">
<?php
echo Html::tag('h4', Yii::t('setup', 'Create administrator account'), ['class' => 'step-title']);
?>
<?php
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_VERTICAL]);
?>
<?php
echo $form->field($model, 'email');
?>
<?php
echo $form->field($model, 'username');
?>
<?php
echo $form->field($model, 'password')->passwordInput();
?>
<?php
echo $form->field($model, 'timezone')->dropDownList($timezones, ['prompt' => Yii::t('setup', '-Select-')]);
?>
<div class="form-action">
<?php
示例12:
$this->registerJs($js);
/** @var \backend\modules\comments\models\CommentForm $model */
echo \Yii::$app->request->isAjax ? '' : Html::beginTag('div', ['class' => 'modal', 'id' => 'allInOneModal']);
?>
<div class="modal-dialog">
<div class="modal-content">
<?php
Pjax::begin(['id' => 'edit_comment', 'enablePushState' => false, 'enableReplaceState' => false, 'timeout' => 10000, 'clientOptions' => ['url' => \yii\helpers\Url::to(['/comments'])]]);
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Редактирование комментария</h4>
</div>
<?php
$form = \kartik\form\ActiveForm::begin(['type' => \kartik\form\ActiveForm::TYPE_HORIZONTAL, 'id' => 'edit-comment-form', 'action' => '/comments', 'options' => ['data-pjax' => true]]);
?>
<div class="modal-body">
<?php
if (\Yii::$app->session->getFlash('saved', false)) {
echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('saved'), 'options' => ['class' => 'alert alert-success alert-dismissible']]);
} else {
if (\Yii::$app->session->getFlash('error', false)) {
echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('error'), 'options' => ['class' => 'alert alert-danger alert-dismissible row col-xs-10 col-xs-offset-1']]);
}
}
echo $form->field($model, 'author'), $form->field($model, 'text')->textarea(), $form->field($model, 'email'), $form->field($model, 'published')->checkbox([], false), $form->field($model, 'deleted')->checkbox([], false), $form->field($model, 'commentID')->hiddenInput(['style' => 'display: none'])->label(false);
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Закрыть</button>
示例13: function
<?php
/** @var \backend\modules\quiz\models\QuizForm $model */
use kartik\form\ActiveForm;
use rmrevin\yii\fontawesome\FA;
use yii\bootstrap\Html;
$js = <<<'JS'
$('#quizAnswersList').addInputArea();
$("body").on('inputArea.added inputArea.removed', "#quizAnswersList", function(){
$("#quizAnswersList .quizAnswersList_del")
});
JS;
$this->registerJsFile('/js/addInputArea.js', ['depends' => 'yii\\web\\JqueryAsset']);
$this->registerJs($js);
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL, 'id' => 'edit-quiz-form', 'options' => ['data-pjax' => true, 'class' => 'editQuizForm']]);
echo $form->field($model, 'name');
?>
<div id="quizAnswersList">
<?php
foreach ($model->answers as $key => $answer) {
echo \yii\helpers\Html::tag('div', $form->field($answer, 'text', ['inputOptions' => ['name_format' => 'QuizAnswerForm[%d][text]'], 'addon' => ['append' => ['content' => Html::button(FA::icon('times'), ['class' => 'quizAnswersList_del btn btn-danger btn-sm', 'style' => 'height: 34px; width: 34px;']), 'asButton' => true]]]) . (!empty($answer->id) ? $form->field($answer, 'id', ['inputOptions' => ['name' => "QuizAnswerForm[{$key}][id]", 'name_format' => 'QuizAnswerForm[%d][id]']])->hiddenInput()->label(false) : ''), ['class' => 'quizAnswersList_var']);
}
?>
</div>
<?php
echo Html::button(FA::icon('plus') . ' Добавить', ['class' => 'quizAnswersList_add btn btn-success btn-sm', 'style' => 'margin: 0px auto; display: block;']) . Html::tag('br'), $form->field($model, 'dateStart')->widget(\kartik\datetime\DateTimePicker::className(), ['pluginOptions' => []]), $form->field($model, 'dateEnd')->widget(\kartik\datetime\DateTimePicker::className(), []), $form->field($model, 'published')->checkbox([], false), $form->field($model, 'deleted')->checkbox([], false), Html::tag('div', Html::button('Сохранить', ['class' => 'btn btn-success btn-lg', 'type' => 'submit']), ['class' => 'text-center']);
$form->end();
示例14: handleMatakuliah
/* @var $this yii\web\View */
/* @var $model backend\modules\aitk\models\AitkRequest */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="aitk-request-form">
<style>
#dataMahasiswa {
display: none;
position: relative;
}
</style>
<?php
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'], 'id' => 'form-request']);
?>
<!--
<script>
function handleMatakuliah(nama) {
var name = nama.split(" ")[0];
$('#ck' + name).click(function () {
$("." + name).remove();
$('.detailMatakuliah:first').clone().insertAfter(".detailMatakuliah").prop({class: name, id: name, style: "display:block"});
$(".control-label").prop("id", "lbl"+name);
if ($("#ck" + name).is(":checked")) {
$(".detailMatakuliah").hide();
$("." + name).show();
示例15:
<?php
use kartik\form\ActiveForm;
/** @var \backend\modules\ads\models\BannerForm $model */
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL, 'id' => 'edit-ad-form', 'options' => ['data-pjax' => true]]);
echo $form->field($model, 'name'), $form->field($model, 'position')->dropDownList($model->possiblePositions), $form->field($model, 'enableDate')->widget(\kartik\datetime\DateTimePicker::className(), []), $form->field($model, 'disableDate')->widget(\kartik\datetime\DateTimePicker::className(), []), $form->field($model, 'code')->textarea(['style' => 'height: 30vh']), $form->field($model, 'state')->checkbox([], false), \yii\bootstrap\Html::tag('div', \yii\helpers\Html::button('Сохранить', ['class' => 'btn btn-success', 'type' => 'submit']), ['class' => 'text-center']);
$form->end();