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
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 2 modals in one active form. Let's say first one is modal-ticket and second one is contract-ticket. First time, I click button to show modal-ticket, and it was fine, but when I click button to show modal-contract, it also call script modal-ticket or otherwise. why?
this is my code.
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalTicketList',
'data-toggle'=>"modal",
'data-target'=>"#modalTicketList",
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalContractList',
'data-toggle'=>"modal",
'data-target'=>"#modalContractList",
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'header' => 'Ticket List',
'id' => 'modalTicketList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentTicket'></div>";
Modal::end();
?>
<?php
Modal::begin([
'header' => 'Contract List',
'id' => 'modalContractList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentContract'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$('#BtnModalTicketList').click(function(e){
e.preventDefault();
$('#modalTicketList').modal('show')
.find('#modalContentTicket')
.load($(this).attr('value'));
return false;
});
$('#BtnModalContractList').click(function(e){
e.preventDefault();
$('#modalContractList').modal('show')
.find('#modalContentContract')
.load($(this).attr('value'));
return false;
});
JS;
$this->registerJs($script);
?>
this are the error found in console web browser
GET http://localhost/pks/web/ticket-timbangan/get-ticket?id=1 404 (Not Found)
GET http://localhost/pks/web/contract/get-contract?id=2 404 (Not Found)
please help.
Try This: using one modal on your form:
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary showModal',
'id' => 'BtnModalTicketList',
'title' => 'Search Ticket',
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary showModal',
'title' => 'Search Contract',
'id' => 'BtnModalContractList',
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'headerOptions' => ['id' => 'modalHeader'],
'id' => 'modal',
'size' => 'modal-lg',
'closeButton' => [
'id'=>'close-button',
'class'=>'close',
'data-dismiss' =>'modal',
],
'class' => 'style=width:auto',
'clientOptions' => [
'backdrop' => false, 'keyboard' => true
]
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$(document).on('click', '.showModal', function(){
if ($('#modal').hasClass('in')) {
$('#modal').find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
} else {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
}
});
JS;
$this->registerJs($script);
?>
From viewing your code what calls my attention is how you use the Url::to() function. Not sure why you use ../. I have fiddled with using more than one modal in a form and the code is similar to what your are doing. I suggest you try changing your Url::to() function as follows:
Url::to('/ticket-timbangan/list')
and
Url::to('/contract/list')
Another suggestion would be to try with
Yii::$app->urlManager->createUrl('/ticket-timbangan/list')
and
Yii::$app->urlManager->createUrl('/contract/list')
Let me know if this helps.
First, many thanks to kalu who has helped me 2 days to solve my problem. Two modals which contains grid need to define different classes to prevent execute previous script.
'value' => Url::to('../ticket-timbangan/list') and 'value' => Url::to('../contract/list'), both has two gridview and same select-row class. This class is root cause of the problem, because it's same class and execute both script.
Thanks Kalu, you save my day.
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 am modifying my login form in CakePHP, and want to add Register Button after Login button. However CakePHP creates line break between these two elements:
My login.ctp file:
<?php
/**
* Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
* #license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<div class="row-fluid">
<div class="span4"></div>
<div class="span4">
<fieldset>
<?php
echo $this->Form->create($model, array(
'plugin' => 'users', 'controller' => 'users',
'language' => $this->Session->read('Config.language'),
'id' => 'LoginForm', 'class' => 'well'));
?>
<div class="row-fluid">
<?php
if ($_SERVER['HTTP_HOST'] == Configure::read('webakis.touchscreen_host')) {
echo $this->Form->input('name', array(
'label' => __('Name'), 'class' => 'span12'));
echo $this->Form->input('surname', array(
'label' => __('Surname'), 'class' => 'span12'));
} else {
echo $this->Form->input('email', array(
'label' => __('Email or name surname'), 'type' => 'text', 'class' => 'span12'));
}
echo $this->Form->input('password', array(
'label' => __('Password'), 'class' => 'span12'));
// echo '<p>' . $this->Form->checkbox('remember_me') . __( 'Remember Me') . '</p>';
//echo '<p>' . $this->Html->link(__( 'I forgot my password'), array('action' => 'reset_password')) . '</p>';
echo $this->Form->hidden('User.return_to', array(
'value' => $return_to));
// echo $this->Form->end(__( 'Sing in') );
?>
<div class="row-fluid">
<?php
echo $this->Form->submit(__('Sign in'), array('class' => 'btn span6'));
echo $this->Html->link(__('Create an Account'), array('plugin' => 'users', 'controller' => 'users', 'action' => 'add'), array('class' => 'btn span6'));
?>
</div>
<p><?php
if ($_SERVER['HTTP_HOST'] !== Configure::read('webakis.touchscreen_host')) {
echo $this->Html->link(__('Forgot your password?'), array('action' => 'reset_password'));
}
?>
</p>
<div class="btn btn-facebook"><i class="fa fa-facebook"></i>
<?php echo $this->Html->link('Connect with Facebook', $fb_login_url);?>
</div></br></br>
</div><?php echo $this->Form->end(); ?>
</form>
</fieldset>
</div>
<div class="span4"></div>
</div>
I have tried to use Bootstrap "row-fluid" class to put them in one line, but it doesn't work.
It's not a linebreak as in <br>, it's that the button is being wrapped in a block element (div by default).
Either disable it
echo $this->Form->submit(__('Sign in'), array(
'class' => 'btn span6',
'div' => false
));
or use the after option to inject your other button/link into the wrapping element:
$link = $this->Html->link(__('Create an Account'), array(
'plugin' => 'users',
'controller' => 'users',
'action' => 'add'
),
array('class' => 'btn span6'));
echo $this->Form->submit(__('Sign in'), array(
'class' => 'btn span6',
'after' => $link
));
See also http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options
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