i'm trying to use a placeholder in my form with i will also want to translate base of user's language so i wrap it up in a Yii::t(); inside active form input attribute but the result i got is a plane string rather than a translated message below is my code:
<div class="input-group custom-d-flex">
<span class="input-group-addon input-group-prepend"><i class="glyphicon glyphicon-user"></i></span>
<?= $form->field($model, 'username')->textInput([
'autofocus' => false,
'class' => 'form-control',
'required' => true,
'placeholder' => "<?= \Yii::t('app', 'email');?> / <?= \Yii::t('app', 'id');?> / <?= \Yii::t('app', 'phone');?>"
])->label(false);
?>
</div>
and the result below
how to fix this? thanks for any help
Placeholder expects string:
'placeholder' => \Yii::t('app', 'email') . ' / ' . \Yii::t('app', 'id') . ' / ' . \Yii::t('app', 'phone'),
Related
I want to update query when user field search field and click on button "search", but this is not send my get parameters to update action ..
here is view:
<?php
Pjax::begin([
'enablePushState' => true, // I would like the browser to change link
'timeout' => 100000 // Timeout needed
]);
echo LinkPager::widget([
'pagination' => $pagination,
'hideOnSinglePage' => true,
'prevPageLabel' => 'Предишна',
'nextPageLabel' => 'Следваща',
'firstPageLabel' => 'Начало',
'lastPageLabel' => 'Край'
]); ?>
<?php $form = ActiveForm::begin([
'action' => ['update'],
'method' => 'get',
]); ?>
<input type="text" id="fname" class="form-control search-option-input" placeholder="търси прецификация по име, номер" name="search-query-main" value=' '>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
i use pjax for pager with result of all specification, because they are over 600 ... this code is in view _form and i want to send it with this search word to controller action Update, who can not work without $_GET['id']
If you want to pass ID in URL you can add it into action URL of your form:
<?php $form = ActiveForm::begin([
'action' => ['update', 'id' => $id],
'method' => 'get',
]); ?>
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(); ?>
yii2 submit button needs to be clicked two times in form
I have a problem where I need to check more than one submit buttons in the controller. It works but I need to click submit buttons two times.
In controller :
switch(\Yii::$app->request->post('submit')) {
case 'submit_1' :
//my code
break;
case 'submit_2' :
//my code
In view
<?= Html::submitButton('NEXT', ['name' => 'submit', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>
There is an issue with using jquery reserved words as your attribute id or attribute names.
Search for "Be careful when naming form elements such as submit buttons" at
https://github.com/yiisoft/yii2/blob/master/docs/guide/input-forms.md
Search "Additional Notes" at https://api.jquery.com/submit/
Changing your submit names will fix your click twice problem:
<?= Html::submitButton('NEXT', ['name' => 'submit_next', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit_prev', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>
try to change name of button as array
<?= Html::submitButton('NEXT', ['name' => 'submit[]', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit[]', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>
and in your controller :
$submittedType = \Yii::$app->request->post('submit');
switch($submittedType[0]) {
//your code
}
To avoid double click disable validate on submit:
$form = ActiveForm::begin([
'validateOnSubmit' => false,
]);
Is it possible to add textboxes to NavBar so that the user can enter username and password into the menubar instead of Login page?
You can add a form in your navbar inside the layout.
the sample provide is for a basic form but you can use an activeForm for yii2 and relate the field to a model (user o LoginForm)
This is a part of main.php layout (in yourapp/frontend/layout ) adn add two input field at the end of navbar..
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'MyBrand',
'brandUrl' => Yii::$app->homeUrl,
'brandOptions' =>[
'style' => 'font-family: palatino; font-size:24px;'
],
'options' => [
//'class' => 'navbar-inverse navbar-fixed-top',
'class' => 'navbar navbar-default navbar-fixed-top',
],
]);
......
.......
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
'encodeLabels' => false,
]);
?>
<form>
First name:
<input style="display: inline;" type="text" name="firstname">
Last name:
<input style="display: inline;" type="text" name="lastname">
</form>
<?php
NavBar::end();
?>
Put this:
$menuItems[] = '<li>'
. Html::beginForm($action = '', $method = '', $options = [])
. Html::textInput('search', '', [])
. Html::endForm()
. '</li>';
Before echo Nav::widget
That is all
I have the following form declaration:
<div class="edit-dialog span-10" style="display:none;">
<div class="edit-message span-10" style="margin-bottom:30px;">
<span>Editing: <a style="text-decoration:none"></a></span>
</div>
<?php
echo $this->Form->create('Voicenote', array('action' => 'edit'));
echo $this->Form->input('title', array(
'div' => false,
'class' => 'input-text recorder',
'label' => array(
'class' => 'inlined',
'text' => ''
),
'id' => 'VoicenoteEditTitle',
'placeholder' => 'Title',
'style' => 'margin-bottom:10px;',
'onsubmit' => 'return false;'
));
echo $this->Form->input('tags', array(
'div' => false,
'class' => 'input-text recorder',
'id' => 'VoicenoteEditTags',
'label' => false,
'placeholder' => 'Tags',
'onsubmit' => 'return false;'
));
echo $this->Form->button('Cancel', array(
'class' => 'button medium blue',
'id' => 'cancel-edit',
'style' => 'float:left;margin-top:50px;'
));
echo $this->Form->submit('Save', array(
'class' => 'button medium blue',
'id' => 'save-edit',
'style' => 'float:right;margin-top:50px;'
));
?>
<input type="hidden" id="edit-container-index" value="">
</div>
It's not outputting the <form></form> tags and I have declared my forms this way throughout my app, adding the $this->Form->end() doesn't work either, any clues?
EDIT: explicitly declaring the <form></form> tags does not output them either
EDIT 2: there is something really weird I'm noticing. I have 4 forms on the page with the problem, If I remove the rendering of the element with the problem, another one of my forms wont render, the one right after it.
you have a submit button. just add end() after submit button in your ctp file.
<?php
echo $this->Form->create('users');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->submit('login');
echo $this->Form->end();
?>
Hi I think if you change last echo to
echo $this->Form->end( array(
'label'=>'Save',
'class' => 'button medium blue',
'id' => 'save-edit',
'style' => 'float:right;margin-top:50px;'
));
it should work