I have used bootstrap modal popup in my site. By clicking the button pop will open. It is working on the following code.
HTML:
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
But the button come from array.
<?php
$args['test'] = array(
array(
'type' => 'submit',
'id' => ' text',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => ''),
);
?>
How can I pass "data-toggle="modal" data-target="#myModal" in array.
Nothing different, just add those attributes in the array like this:
array(
'type' => 'submit',
'id' => ' musicfileupload',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => '',
'data-toggle' => 'modal', // <--
'data-target' => '#myModal' // <--
);
Update: Following is a working example:
$data = array(
'type' => 'submit',
'id' => ' musicfileupload',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => '',
'data-toggle' => 'modal', // <--
'data-target' => '#myModal' // <--
);
echo form_button($data);
Related
i'm trying without success to add an image inside a Navbar menuItem.
It works fine in the brandLabel
But doesn't work on anoter menu item
(I Want to display the logged user image near his name)
I Tryed several times but doesnt seem to make it work,
Would apreciate your help please...
The Code is this:
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Html::img('#themes'.'/siteImages/Logo.jpg', ['alt'=>Yii::$app->name]),
'options' => [
'class' => 'navbar-default navbar-fixed-top',
],
]);
// display Login page to guests of the site
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login'],
'options' => [
'class' => 'navbar-right',
],];
}
else
{
// Show sales content to sales+ users
if ( Yii::$app->user->can('useSalesContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Sales'),
// 'class' => "pull-left",
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'sales',
'class' => 'navbar-left',
],
];
// Show Admin content to manager+ users
if (Yii::$app->user->can('useAdminContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Administration'),
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'admin'],
'options' => [
'class' => 'navbar-left',
],];
}
// display Logout to logged in users
if (!Yii::$app->user->isGuest) {
$menuItems[] =
[
'label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user-
>identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
//****** This is where I want the user image to be shown ****//
];
}
}
// echo navbar with selected items
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Alert::widget() ?>
<?= $content ?>
</div>
endBody() ?>
Provided the user model has an attribute imageUrl it would be accessible through:
Yii::$app->user->identity->imageUrl
This would become something like:
If you would like to add it to the logout button:
$menuItems[] = [ 'encode'=>false, label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user- >identity->username . ') ' . Html::img(Yii::$app->user- >identity->imageUrl), 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']];
make sure you include 'encode' => false,
To add it as a separate item (for instance, to give it a different link):
$menuItems[] = [ 'encode' => false, 'label' => Html::image(Yii::$app->user- >identity->imageUrl)];
Edit:
Make sure you include the Html with a use statement in your view, or provide the full namespace declaration with Html class.
I have add a button within admin form as follows.
$fieldset->addField('registered', 'button', array(
'label' => Mage::helper('core')->__('Send e-mail to all registered customers'),
'value' => Mage::helper('core')->__('Button Caption'),
'name' => 'registered',
'onclick' => "setLocation('{$this->getUrl('*/*/registeremail')}')",
));
The functionality of this field working properly but the button does not appear properly. It appears as follows.
How to appear this button as normal magento button?
I have tried with
'after_element_html' => '<button type="button" onclick="setLocation('{$this->getUrl('*/*/registeremail')}')">All Registered</button>'
But onclick call is wrong.
Try
$fieldset->addField('registered', 'button', array(
'label' => Mage::helper('core')->__('Send e-mail to all registered customers'),
'value' => Mage::helper('core')->__('Button Caption'),
'name' => 'registered',
'class' => 'form-button',
'onclick' => "setLocation('{$this->getUrl('*/*/registeremail')}')",
));
This works for me.
I wanted to fetch the selected value from the database and display it in codeigniter form_dropdown() function but it displays wrong.
Controller:
$type = array(
'options' => array(
'section' => 'Section',
'transaction' => 'Transaction',
'document' => 'Document'
),
'attributes' => array(
'class' => 'form-control'
)
);
View:
<?php echo form_dropdown('type', $type['options'],'', $type['attributes']) ?>
The Screenshot
Try the below code:
Controller:
$this->data['type'] = array(
'name' => 'type_value',
'attributes' => 'class="form-control"',
'value' => (isset($database_type_value) && trim($database_type_value)) ? $database_type_value: $this->input->post('type_value',TRUE), //$database_type_value - value from database
'options_list' => array(
'section' => 'Section',
'transaction' => 'Transaction',
'document' => 'Document'
),
);
View:
<?php echo form_dropdown($type['name'],$type['options_list'],$type['value'],$type['attributes']);?>
Problem in dependent dropdowns when editing in my yii application.
While editing, the drop downs are not automatically selected.
In my view,
array('class' => 'CButtonColumn',
'header' => 'Manage',
'template' => '{update} {view} {delete}',
'htmlOptions' => array('width' => '20%'),
'buttons' => array(
'update' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-pencil'),
),
'view' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-eye-open'),
),
'delete' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-remove'),
),
),
),
<div class="form-group">
<label for="reg_input" class="req">Course</label>
<?php
$course = CHtml::listData(Course::model()->findAll(), 'courseid', 'course_name');
echo CHtml::activeDropDownList($model, 'courseid', $course, array(
'empty' => 'Select Course', 'class' => "form-control",
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Assignment/Fetchbatch'),
'update' => '#' . CHtml::activeId($model, 'batchid'))));
?>
<?php echo $form->error($model, 'courseid', array('class' => 'school_val_error')); ?>
</div>
<div class="form-group">
<label for="reg_input" class="req">Batch</label>
<?php
$batch = CHtml::listData(Batch::model()->findAll(), 'batchid', 'batch_name');
echo $form->dropDownList($model, 'batchid', $batch, array('prompt' => 'Select Batch',
'class' => "form-control",
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Assignment/Fetchsubject'),
'update' => '#' . CHtml::activeId($model, 'subjectid'))));
echo $form->error($model, 'batchid', array('class' => 'school_val_error'));
?>
</div>
Second dropdown get the data, to change of first dropdown. At this condition the dropdown will not be selected automatically. Because when editing, that value is not there. So I fixed this problem, my code is above this.
I created custom module and now from admin side on edit form i added extra field select type.
I want to change comments with onchange function for this specific field.See below my code.
$eventElem = $fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
));
$eventElem->setAfterElementHtml("<script type=\"text/javascript\">function checkSelectedItem(selectElement){}</script>");
This is my code i alert the value and i got my value but it cannot show it in comments area .Did someone one know how to fix it ?
Thanks
This will update the comment (onchange) with the current selected option
$fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
)
))->setAfterElementHtml("<small id='banner_type_comment'>Comments</small>
<script type=\"text/javascript\">
function checkSelectedItem(selectElement){
$('banner_type_comment').update($('banner_type')[$('banner_type').selectedIndex].text);
}
</script>");