How to reduce column gaps in yii/bootsrap/activeform (Yii2)? - php

I am using yii/bootrap/active form and I set the layout to Horizontal
How can I reduce a gap between two columns ? I mean, where is the CSS file in yii/bootrap/activeform ?
My view code is like this
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Modal;
use yii\helpers\BaseHtml;
use app\assets\myassets\InputAsset;
?>
<?php
$listData = ['1' => 'Ya', '0' => 'Tidak'];
$button = Html::button('Cancel', ['class' => 'btn btn-default btn-md', 'data' => ['dismiss' => "modal"]]);
$button .= Html::button('Submit', ['id' => 'submit', 'class' => 'btn btn-success success btn-md']);
Modal::begin([
'header' => '<h2>Konfirmasi</h2>',
'toggleButton' => false,
'id' => 'confirm-submit',
'footer' => $button
]);
echo 'Data ini akan disimpan ?';
Modal::end();
?>
<div class="jenis-form">
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'id' => 'marketing',
'action' => ['index'],
'method' => 'get',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-2',
'offset' => 'col-sm-offset-2',
'wrapper' => 'col-sm-4',
],
],
]);
?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'jn_byr')->textInput(['readonly' => !$model->isNewRecord,'autofocus'=>$model->isNewRecord,]) ?>
<?= $form->field($model, 'nama')->textInput(['autofocus'=>!$model->isNewRecord,]) ?>
<?= $form->field($model, 'ket_dnd')->textInput() ?>
<?= $form->field($model, 'ket_bat')->textInput() ?>
<?= $form->field($model, 'ket_tts')->textInput() ?>
<?= $form->field($model, 'k_inv')->textInput() ?>
</div>
<div class="col-md-6">
<?= $form->field($model, 'ket_battg')->textInput() ?>
<?= $form->field($model, 'ketkw')->textInput() ?>
<?= $form->field($model, 'ketrk')->textInput() ?>
<?= $form->field($model, 'tagih[]')->dropDownList($listData,['prompt'=>'<<< Pilih >>>']); ?>
<?= $form->field($model, 'deposit')->dropDownList($listData,['prompt'=>'<<< Pilih >>>']); ?>
</div>
</div>
<div>
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

Related

Getting unknown property: app\models\LoginForm::email

I bet under the {use app\models\LoginForm} error, but again it gives me the same error.
How to fix that error?
Unknown Property – yii\base\UnknownPropertyException Getting unknown
property: app\models\LoginForm::email
The following code:
use app\models\LoginForm;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="leave-comment mr0"><!--leave comment-->
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'layout' => 'horizontal',
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
<?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox([
'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
]) ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
</div>
It means that you don't have email attribute in LoginForm model, you should declare it in your model.

Yii2 Basic display create from from another model to a view from another model

I create a CRUD called Channel and a CRUD Post, so I want to add create Post form to DetailView of Channel; example when a user view Channel Alpha under the Alpha details he have a form from Post to create a Post inside that Channel
user can view the detail of a Channel and also can add Post to that Channel
something similar to :
in Channel controller
public function actionView($id)
{
$ly_addPost = new Posts();
return $this->render('view', [
'model' => $this->findModel($id),
'addpost' => $ly_addPost,
]);
}
and in channel view I did edit it to :
//Yii2 code
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ActiveForm;
/* #var $this yii\web\View */
/* #var $model app\models\Channel */
$this->title = $model->Channel_name;
$this->params['breadcrumbs'][] = ['label' => 'Channels', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="channel-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->Channel_id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->Channel_id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<div class="col-md-12">
<?= $this->render ('_form', [
'addpost' => $ly_addPost,
])
?>
<div class="posts-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'Posts_title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Posts_text')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Posts_file')->textInput(['maxlength' => true]) ?>
<?php //= $form->field($model, 'Posts_crdate')->textInput() ?>
<?= $form->field($model, 'Channel_id')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Permissions_id')->textInput() ?>
<?php //= $form->field($model, 'user_id')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
but I get error :
PHP Notice – yii\base\ErrorException
Undefined variable: ly_addPost
Change addpost to ly_addPost show below
public function actionView($id)
{
$ly_addPost = new Posts();
return $this->render('view', [
'model' => $this->findModel($id),
'ly_addPost' => $ly_addPost,
]);
}
Just Change $ly_addPost to $addpost in view file
<div class="col-md-12">
<?= $this->render ('_form', [
'addpost' => $addpost,
])
?>
...

create pjax form inside a active form yii2

I can't create a Pjax form inside an active form. What I've found is that when I put the Pjax inside an active form it doesn't work (it submits the entire page) but when I put it outside the active form its works fine:
<?php
$form = ActiveForm::begin([
'id' => 'CouplePartnerForm',
'action' => ['couple-partner/savecouplepartner'],
'enableAjaxValidation' => true,
'enableClientValidation' => true,
'validateOnSubmit' => true,
]);
?>
<div class="row">
<?php Pjax::begin([]); ?>
<?= Html::beginForm(['couple-partner/form-submission'], 'post', ['data-pjax' => '0', 'class' => 'form-inline']); ?>
<?= Html::input('text', 'string', Yii::$app->request->post('string'), ['class' => 'form-control']) ?>
<?= Html::submitButton('Hash String', ['class' => 'btn btn-lg btn-primary', 'name' => 'hash-button']) ?>
<?= Html::endForm() ?>
<h3><?= isset($stringHash) ?$stringHash :"" ?></h3>
<?php Pjax::end(); ?>
</div>
<?php ActiveForm::end(); ?>
So what is the problem here?

Form update using modal in yii2 strange

I've tried for created form update using modal in yii2. The problem is every I change one field with the other value, the result form update with modal closed and redirect to index. And message update can't display in index. I don't know why, maybe wrong in code controller.
Code actionUpdate in controller
public function actionUpdate($id)
{
$model = CalonKeluargaAsuh::findOne($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', 'Data berhasil diubah!');
return $this->redirect(['index']);
return $this->refresh();
} else {
if (Yii::$app->request->isAjax) {
return $this->renderAjax('update', ['model' => $model]);
}
else{
return $this->render('update', ['model' => $model]);
}
}
}
Code form in view
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\widgets\Pjax;
?>
<h2 align="center">Ubah Data Calon Keluarga Asuh</h2>
<?php
echo "&nbsp";
echo "&nbsp";
?>
<?php $form = ActiveForm::begin(['layout' => 'horizontal', 'enableAjaxValidation' => true,
'id' => 'update-form',
]); ?>
<?= $form->field($model, 'kode_calon_keluarga_asuh')->textInput(['readOnly' => true, 'style' => 'width:350px' ]) ?>
<?= $form->field($model, 'nama')->textInput(['style' => 'width:350px']) ?>
<?= $form->field($model, 'jenis_kelamin')->dropDownList(['Laki-laki' => 'Laki-laki', 'Perempuan' => 'Perempuan'],
['prompt'=>'--Pilih--', 'style' => 'width:350px']) ?>
<?= $form->field($model, 'pekerjaan')->textInput(['style' => 'width:350px']) ?>
<?= $form->field($model, 'alamat')->textArea(['rows' => 3, 'style' => 'width:350px']) ?>
<?= $form->field($model, 'telepon')->textInput(['style' => 'width:350px']) ?>
<div class="form-group">
<div class="col-sm-offset-4">
<?= Html::submitButton('Ubah', ['class' => 'btn btn-primary']) ?>
<?php
echo "&nbsp";
echo "&nbsp";
echo Html::a('Keluar', ['index'],[
'class'=>'btn btn-success',
'onclick' =>'$("#calonModal").modal("hide");
return false;'
]);
?>
<?php ActiveForm::end();?>
Code index.php in view
<?php \yii\widgets\Pjax::begin(['timeout' => false, 'id' => 'pjax-gridview']); ?>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\bootstrap\Modal;
use yii\helpers\Url;
/* #var $this yii\web\View */
/* #var $searchModel app\models\SearchDonatur */
/* #var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Data Calon Keluarga Asuh';
?>
<?php if (Yii::$app->session->hasFlash('success')): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-check"></i>Informasi!</h4>
<?= Yii::$app->session->getFlash('success') ?>
</div>
<?php endif; ?>
<?php if (Yii::$app->session->hasFlash('delete')): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-check"></i>Informasi!</h4>
<?= Yii::$app->session->getFlash('delete') ?>
</div>
<?php endif; ?>
<div class="calon-keluarga-asuh-index">
<?php Pjax::begin(['timeout'=>false,'id'=>'pjax-gridview']); ?>
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Tambah Data', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'emptyCell' => '-',
'summary' => '',
'columns' => [
[
'attribute' => 'kode_calon_keluarga_asuh',
'value' => 'kode_calon_keluarga_asuh',
'contentOptions' => ['style' => 'width: 100px;']
],
[
'attribute' => 'nama',
'value' => 'nama',
'contentOptions' => ['style' => 'width: 250px;']
],
[
'attribute' => 'jenis_kelamin',
'value' => 'jenis_kelamin',
'contentOptions' => ['style' => 'width: 100px;']
],
[
'attribute' => 'pekerjaan',
'value' => 'pekerjaan',
'contentOptions' => ['style' => 'width: 200px;']
],
[
'attribute' => 'alamat',
'value' => 'alamat',
'contentOptions' => ['style' => 'width: 210px;']
],
[
'attribute' => 'telepon',
'value' => 'telepon',
'contentOptions' => ['style' => 'width: 100px;']
],
[
'class' => \yii\grid\ActionColumn::className(),
'header' => 'Aksi',
'template' => '{update} {delete}',
'buttons' => [
'update' => function($url, $model) {
$icon = '<span class="glyphicon glyphicon-pencil"></span>';
return Html::a($icon, $url,[
'data-toggle' => "modal",
'data-target' => "#calonModal",
]);
},
'delete' => function($url, $model) {
$icon = '<span class="glyphicon glyphicon-trash"></span>';
return Html::a($icon, $url,
[
'data-confirm' => "Apakah yakin dihapus ?",
'data-method' => 'post',
]);
},
]
],
],
]); ?>
<?php \yii\widgets\Pjax::end() ?>
<?php Pjax::end(); ?>
</div>
<?php
Modal::begin(['id' => 'calonModal']);
Pjax::begin(['id'=>'pjax-modal', 'timeout'=>false,
'enablePushState'=>false,
'enableReplaceState'=>false,]);
Pjax::end();
Modal::end();
?>
<?php
$this->registerJs('
$("#calonModal").on("shown.bs.modal", function (event) {
var button = $(event.relatedTarget)
var href = button.attr("href")
$.pjax.reload("#pjax-modal", {
"timeout":false,
"url":href,
"replace":false,
});
})
');
?>

Yii2 Basic Background change

Im using bootstrap and Im trying to set a background image for the login screen.I try with div with id that catch all the things and set the background but didnt work .
Here my Login.php
<div id="bimg">
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<?php
$form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n <div class=\"center\"><div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div></div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]);
?>
<?= $form->field($model, 'email')->textInput(['autofocus' => true, 'placeholder' => 'Write your email address']) ?>
<?= $form->field($model, 'password')->passwordInput(['placeholder' => 'Write your password']) ?>
<?=
$form->field($model, 'rememberMe')->checkbox([
'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
])
?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<div>
<?= Html::a(Yii::t("app", "Forgotten password") . "?", ["/site/forgot"]) ?>
<br>
</div>
<br>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
and the class with path in bootstrap.css
#bimg{
width:100%;
background-image: url(../web/assets/css/images/5.jpg) !important;
}
In layouts-main.php
controller->action->id == 'login') ? 'background-wrapper' : NULL ?>">
Check on which page u are , and if u are the page u want set the "class" u want

Categories