i got problem when i tried to post submitbutton value.
<?= Html::submitButton('Save', ['value' => 'save','class' => 'btn green','name' => 'submit']) ?>
When i tried with that code, my value posted but i should click the button twice.
<?= Html::submitButton('Save', ['value' => 'save','class' => 'btn green','name' => 'button1']) ?>
But when i changed name button, the value not post.
Any idea to solve this problem?
This my form :
<?php $form = ActiveForm::begin(); ?>
<?= Html::activeDropDownList($storev, 'id_store_v',$itemsv,
[
'prompt'=>'--Select Dealer--',
'class'=>'form-control input-sm select2-multiple',
//'onchange'=>'$("#namev").val($("#id_store_v option:selected").text());',
'onchange'=>'$("input#idv").val($(this).val()),
$.post("index.php?r=sync/listsv&id='.'"+$(this).val(), function( data ) {
$("select#storev-address").html(data);
});'
])
?>
<?= $form->field($storev, 'id_store_v')->hiddenInput(['maxlength' => true, 'id'=>'idv'])->label(false) ?>
<?= $form->field($storev, 'address')->dropDownList(
ArrayHelper::map(Storev::find()->all(),'id_store_v','address'),
[
'prompt'=>'',
'class'=>'form-control input-sm select2-multiple',
'disabled'=> true,
])
?>
<?= Html::activeDropDownList($storetd, 'id',$itemstd,
[
'prompt'=>'--Select Dealer--',
'class'=>'form-control input-lg select2-multiple',
'multiple'=>'multiple',
//'onchange'=>'$("#namev").val($("#id_store_v option:selected").text());',
'onchange'=>'$("input#idtd").val($(this).val())'
])
?>
<?= $form->field($storetd, 'id')->hiddenInput(['maxlength' => true, 'id'=>'idtd'])->label(false) ?>
<?= Html::submitButton('Save', ['value' => 'save','class' => 'btn green','name' => 'button1']) ?>
<?= Html::submitButton('Check', ['value' => 'check','class' => 'btn yellow','name' => 'button1']) ?>
try using a simple
<?= Html::submitButton('Save', ['class' => 'btn btn-green']) ?>
and if you need a value try
<?= Html::submitButton('Save', ['class' => 'btn btn-green', 'value'=>'save' ]) ?>
Try this one
View:
<?= Html::submitButton('Save', ['name' => 'form', 'value' => 'one']) ?>
Controller
if(Yii::$app->request->post('form') == 'one'){
}
Related
I have a form field "dob[]" with array input like
<?php $form = ActiveForm::begin();
for($i=0;$i<= 3;$i++):
echo $form->field($model, 'dob[]')->widget(DatePicker::classname(), [
'options' => ['placeholder' => 'Date Of Birth'],
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'format' => 'mm/dd/yyyy',
'autoclose' => true,
]
]);
endfor; ?>
<div class="form-group">
<?= Html::button('Submit', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
Datepicker working only on first "dob" field but rest of the field having only button format of datepicker but calendar not working.
This is because the javascript cannot determine the correct input fields, after the first one. Take a look in your source code. All widgets have properly the same id and/or name. You have to setup a unique ID for each of the generated widgets.
By the way, it is always a good approach to name form data accordingly.
That is documented at the demo page.
The following should work:
<?php
$form = ActiveForm::begin();
for ($i=0; $i < 3; $i++) {
echo $form->field($model, 'date_end')->widget(DatePicker::classname(), [
'options' => [
'placeholder' => 'Date Of Birth',
'name' => 'DOB' .$i,
'id' => 'DOB-ID' . $i,
],
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'format' => 'mm/dd/yyyy',
'autoclose' => true,
],
]);
}
?>
<div class="form-group">
<?= Html::button('Submit', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
I have a simple form:
<?php $form = ActiveForm::begin([
'id' => 'answer-form',
'action' => Yii::$app->getUrlManager()->createUrl('test'),
'enableClientValidation' => false,
]); ?>
<?= $form->field($user_answer, 'user_text')->textInput(['value' => $text])->label('Text') ?>
<?php ActiveForm::end(); ?>
I want to show input with red color (div with class "has-error" by default)- like somebody added wrong data to the input. How can i do it?
Try this
<?= $form->field($user_answer, 'user_text', [ 'options' => [ 'class' => 'has-error'])->textInput(['value' => $text])->label('Text') ?>
getting an error cant upload the extension kartik select2....
need some ideaaa
using yii want to install the select 2 extension in the branch table...
<div class="branches-form">
<?php $form = ActiveForm::begin(); ?>
<?=$form->field($model,'companies_company_id')->widget(Select2::classname(), [
'data' =>ArrayHelper::map(Companies::find()->all(),'company_id','company_name'),['prompt'=>'Select Company'] ,
'language' => 'en',
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions'=> [
'allowClear' => true
],
]); ?>
<?= $form->field($model, 'branch_name')->textInput(['maxlength' => 100]) ?>
<?= $form->field($model, 'branch_address')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'branch_status')->dropDownList([ 'active' => 'Active', 'inactive' => 'Inactive', '' => '', ], ['prompt' => 'Status']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Properly read this documentation http://demos.krajee.com/widget-details/select2
Try this solution:
Also include use kartik\select2\Select2; at the top of your file.
<?= Select2::widget([
'attribute' => 'companies_company_id',
'model' => $model,
'data' =>ArrayHelper::map(Companies::find()->all(),'company_id','company_name'),['prompt'=>'Select Company'] ,
'language' => 'en',
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions'=> [
'allowClear' => true
],
]) ?>
My application have to have multiple language, so I decided to separate each language by using tab (Yii2 gui), but how can I render the form in side the 'content' key?
<?php
$language_tab=[];
$increment=0;
$content="I love you";
foreach($language as $obj){
$language_tab[$increment] = array('label' => $obj->name ,'content' => $content);
$increment++;
}
echo Tabs::widget([
'items' => $language_tab,
'options' => ['tag' => 'div'],
'itemOptions' => ['tag' => 'div'],
'headerOptions' => ['class' => 'my-class'],
'clientOptions' => ['collapsible' => false],
]);
?>
<div class="status-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'date_created')->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>
I just wanna change from $content to the form below.
Please help!!!
You may create separate view for the form and render it:
...
'content' => $this->render('_language_form', ['language' => $obj, 'model' => $model]),
...
I'm creating a form view and I want to organize the form fields with tabs structure, using the official Tabs widget.
Is it possible init the Tabs widget with the id (or class) of the div elements that contains the active form fields?
One example of how you can manage it is doing like this:
First, divide your contact-form into one view-file for each tab.
Place the ActiveForm::begin() and ActiveForm::end() around the Tabs::widget()
Render the contact-form pages into content, with parameters $model and $form
Example code:
views/site/contact.php
<?php
/* #var $this yii\web\View */
$this->title = 'Contact';
use yii\bootstrap\Tabs;
use yii\bootstrap\ActiveForm;
?>
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= Tabs::widget([
'items' => [
[
'label' => 'One',
'content' => $this->render('contact_form1', ['model' => $model, 'form' => $form]),
'active' => true
],
[
'label' => 'Two',
'content' => $this->render('contact_form2', ['model' => $model, 'form' => $form]),
],
]]);
?>
<?php ActiveForm::end(); ?>
views/site/contact_form1.php
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
views/site/contact_form2.php
<?php
use yii\helpers\Html;
use yii\captcha\Captcha;
?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
Hope this helps!
Just add at the top of your contact.php global $form; and all works fine.
I have another solution:
When we call $form->field($model, 'name')->textInput(), it will return the model of class yii\widgets\ActiveField, so just continue calling a method of this class as $form->field($model, 'name')->textInput()->render(). It will return a string then you can use it for the tab's content.
I have an example code in my application for translating multi languages as the following code:
<?php
$items = [];
foreach ($translateModels as $translateModel) {
$tabContent = $form->field($translateModel, "[{$translateModel->code}]name")->textInput()->render();
$items[] = [
'label' => $translateModel->language->name,
'content' => $tabContent,
];
}
?>
<?= Tabs::widget([
'options' => [
'class' => 'nav-tabs',
'style' => 'margin-bottom: 15px',
],
'items' => $items,
]) ?>
Maybe it's help.