Yii2 Basic Background change - php

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

Related

How to customize validation error message to display on tooltip in Yii2?

I am using ActiveForm of yii2 and I want to customize the validation errors. I want to display errors on tooltip.
This is my form
<?= $form = ActiveForm::begin(['id' => 'login-form','method'=>'post']); ?>
<?=
$form->field($model, 'email')
->textInput([
'class'=>'form-control login_email',
'placeholder'=>'Email'
/*'onfocus'=>"this.value = '';",
"onblur"=>"if (this.value == '') {
this.value = 'Email';
}"*/
])
->label(false);
?>
<?=
$form->field($model, 'password')
->passwordInput([
'class'=>'form-control',
'placeholder'=>'Password'
])
->label(false);
?>
<input type="text" name="hidden" value="login" hidden="true">
<p class="forgot">
<a href="<?= Yii::$app->urlManager->createUrl(['site/request-password-reset']); ?>">
Forgot Password?
</a>
</p>
<div class="form-group">
<?= Html::submitButton('Log In', ['class' => 'sign-in','name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
Please tell me if anyone has idea about this.
Update error message in form template like below
$form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['enctype' => 'multipart/form-data'],
'fieldConfig' => ['template' => "<div class=\"input-cover\"><div class=\"tooltip\">{error}</div>\n{label}\n{input}</div>",
'inputOptions' => ['class' => 'input-control'],
],
]);

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 display error msg

displaying msg on above the line, how to display error msg below line. I have added below view page. any suggestions.
below is view page
<div class="ibox-content bwform clearfix" id="bwcart">
<h2><b>Profile</b><div id="loader"></div></h2>
<?php $form = ActiveForm::begin(
['action' =>'',
'options' => ['method'=>'post','class'=>'form-horizontal','id'=>'profile-form','enctype'=>'multipart/form-data'],
'fieldConfig' => [
'template' => "{label}<div class=\"col-md-12\">{input}\n{error}</div>",
'labelOptions' => ['class' => 'col-lg-12 control-label p-l-0'],
],
'enableAjaxValidation'=>true,'enableClientValidation' => true,'validateOnSubmit'=>true]); ?>
<div class="box-2">
<div class="input input--hoshi <?=$prefilled ?>">
<?= $form->field($model, 'firstname')->textInput(array('placeholder' => '','class'=>'input__field input__field--hoshi'))->label(false); ?>
<label class="input__label input__label--hoshi input__label--hoshi-color-3" for="first_name">
<span class="input__label-content input__label-content--hoshi">First Name</span>
</label>
</div>
</div>
<div class="box-2">
<div class="input input--hoshi <?=$prefilled ?>">
<?= $form->field($model, 'lastname')->textInput(array('placeholder' => '','class'=>'input__field input__field--hoshi'))->label(false); ?>
<label class="input__label input__label--hoshi input__label--hoshi-color-3" for="first_name">
<span class="input__label-content input__label-content--hoshi">Last Name</span>
</label>
</div>
</div>
You can use this solution:
<?php $form = ActiveForm::begin(
['action' =>'',
'options' => ['method'=>'post','class'=>'form-horizontal','id'=>'profile-form','enctype'=>'multipart/form-data'],
'fieldConfig' => [
//modify this
'template' => "{label}<div class='col-md-12'>{input}</div><div class='col-md-12 '>{error}</div>",
'labelOptions' => ['class' => 'col-lg-12 control-label p-l-0'],
],
'enableAjaxValidation'=>true,'enableClientValidation' => true,'validateOnSubmit'=>true]); ?>
So your error tag is positioned
under your input tag.
Your error attribute should not be in your col-md-12 class div.
So it should be like this:
<?php $form = ActiveForm::begin(
['action' =>'',
'options' => ['method'=>'post','class'=>'form-horizontal','id'=>'profile-form','enctype'=>'multipart/form-data'],
'fieldConfig' => [
'template' => "{label}<div class=\"col-md-12\">{input}</div>{error}",
'labelOptions' => ['class' => 'col-lg-12 control-label p-l-0'],
],
'enableAjaxValidation'=>true,'enableClientValidation' => true,'validateOnSubmit'=>true]); ?>

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

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>

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?

Categories