I want to pass a php variable to modal window , what i am doing is opening a modal window using this link , but i want to pass a variable to this link and get same variable in modal window , i try to to do this to append a text in some div but it return html that i am unable to get in query
echo CHtml::link(
'Set Recipe', '', array(
'class' => 'testclass',
'id' => $finalDate,
'data-toggle' => 'modal',
'data-target' => '#myModal',
'fahadVar' => $finalDate
));
and when i click this button i got modal window how to get variable set in button
Here is simple modal code of yiibooster
<div class="modal-body">
<p>One fine body...</p>
</div>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'label' => 'Save changes',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Close',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
thanks in advance
You should create a Widget.
Note: I copied below from another post. It works like charm.
First Create a new widget. Let say the name is CategoryWidget. Put this widget under components directory protected/components.
class CategoryWidget extends CWidget {
public function run() {
$models = Category::model()->findAll();
$this->render('category', array(
'models'=>$models
));
}
}
Then create a view for this widget. The file name is category.php. Put it under protected/components/views
category.php
<?php if($models != null): ?>
<ul>
<?php foreach($models as $model): ?>
<li><?php echo $model->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Then call this widget from your main layout.
main.php
// your code ...
<?php $this->widget('CategoryWidget') ?>
Related
Each model id has a corresponding static page e.g id = 1 of my table has a static page in my views as 1.php. So when i click the link button (implemented in ClistView) it respective static page should be displayed.
How can i implement this functionality?
<?php
echo CHtml::link('View Detail', array('$data->id.php'),
// i want 1.php to be displayed for $data->id =1 and 2.php for $data->id= 2
array('id'=>'mylink','class'=>'btnPrint btn btn-danger',
'target'=>'_blank',
));
?>
<?php
echo CHtml::link(
'View Detail',
$this->createUrl('site/static', array('id' => $data->id)),
array(
'id' => 'mylink',
'class' => 'btnPrint btn btn-danger',
'target' => '_blank',
)
);
And in your controller you can create an action as follows:
public function actionStatic($id)
{
$this->render($id);
}
I am new to drupal.
I need to customize a registration form by adding fields like id,mobile etc.
Can I accomplish this by creating a custom module?
If yes could anyone please help me with a brief idea on creating and overriding the default user registration submit function. I have to insert these details to another table and also have to pass the data as a service request.
Ive created a custom module with function
module_form_alter(&$form,&$form_state,$form_id){
$form['#submit'] = 'module_form_submit';
if($form_id == 'user_register_form'){
//print_r($form_id);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('id'),
'#default_value' => '',
'#size' => 60,
'#maxlength' => 15,
'#required' => TRUE,
);
}
}
function module_form_submit($form, &$form_state){
echo "test";
exit();
}
module_form_alter is being called and I can see the new field on the registration screen but the submit function is still not called. I need to override the default drupal register submit.
I already have the following function in my theme template.php
function templatename_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'portal_preprocess_user_login'
),
);
$items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-register-form',
'preprocess functions' => array(
'portal_preprocess_user_register_form'
),
);
$items['user_pass'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-pass',
'preprocess functions' => array(
'portal_preprocess_user_pass'
),
);
return $items;
}
user-register-form.tpl.php
<div class="form-group">
<?php print drupal_render_children($form); ?>
</div>
And page--user--register.tpl.php with the html
<div id="login-page">
<div class="container">
<div class="form-login" >
<h2 class="form-login-heading"><img src="<?php echo drupal_get_path('theme', 'portal') . '/images/logo.png'; ?>" width="100"><?php echo $createaccount; ?></h2>
<div class="login-wrap">
<?php
$elements = drupal_get_form("user_register_form");
$form = drupal_render($elements);
echo $form ?>
<?php if ($messages):?>
<div id="messages-console" class="clearfix">
<div class="grid_12">
<div class="mt-grid-fix">
<?php print $messages; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
Is this approach fine or should I change this approach inorder to make my custom module functional?
You can go to:
admin/config/people/accounts/fields
and add the fields that you need.
In the fieldset "User settings" don't forget check "Display on user registration form."
I have three buttons which open 1 modal window on a page:
<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'myModal',)); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4 class="text-center">Pay</h4>
</div>
<div class="modal-body">
<?php
$this->widget('bootstrap.widgets.TbDetailView', array(
'type'=>'bordered condensed',
'data'=>$model,
'attributes'=>array(
array(
'type'=>'raw',
'label'=>'Период',
'value'=> '', // if (clicked button id is 1 value == 1 day) else if (clicked button id is 2 value == 7 days)
),
),
));
?>
</div>
<div class="modal-footer">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'type'=>'primary',
'label'=>'Проверить',
'url'=>'#',
'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>
</div>
<?php $this->endWidget(); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'encodeLabel' => false,
'label'=>'1 day',
'type'=>'primary',
'htmlOptions'=>array(
'id' => '1',
'onclick' => 'alert(this.id)',
'data-toggle'=>'modal',
'data-target'=>'#myModal',
),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'encodeLabel' => false,
'label'=>'7 dayss',
'type'=>'primary',
'htmlOptions'=>array(
'id' => '2',
'onclick' => 'alert(this.id)',
'data-toggle'=>'modal',
'data-target'=>'#myModal',
),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'encodeLabel' => false,
'label'=>'1 month',
'type'=>'primary',
'htmlOptions'=>array(
'id' => '3',
'data-toggle'=>'modal',
'data-target'=>'#myModal',
),
)); ?>
How to pass the clicked button id to TbButton value?
if (clicked button id is 1 value == 1 day) else if (clicked button id is 2 value == 7 days) ...
First of all, id of elements on website need to be unique, you may want to consider using data attributes or calling those id differently.
Next thing is that only button that is submitting form is passing value with form to the server so you either need to use hidden input field or submit form by pressing that button or submit form using ajax request and attach it manually.
As I see you have put onclick event directly in element, better solution would be to put it outside in separate script tag/script file, but it is outside of your question.
What you need to do to assign value to be sent with form is to use following js to:
Assign code to input field:
$('#length_field').val(this.id)
or without jQuery:
document.getElementById('length_field').value = this.id
if you will use data-time-length="7" instead of id then you can do it by:
$('#length_field').val($(this).data('time-length'))
However it is unclear to me where you want to pass this value, what you want to do with it.
I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.
but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?
In my Controller
$dataProvider=new CActiveDataProvider('Store',
array(
'criteria' => array(
'condition'=>$_search_conditions,
'params'=>$search_params,
),
'sort'=>array(
'defaultOrder'=>'store DESC',
'attributes'=>array(
'store'=>array(
'asc'=>'store',
'desc'=>'store DESC',
),
'*',
)
),
)
);
$model = new Store;
$model->unsetAttributes(); // clear any default values
//render page
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model
));
In my View
$this->widget('zii.widgets.CListView', array(
'id' => 'store-list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enableHistory'=> true,
'pagerCssClass' => 'pagination',
'ajaxUpdate'=>'store-list',
'loadingCssClass' => '', //remove loading icon
'sortableAttributes'=>array(
'store',
//'state' => 'State',
//'distance' => 'Distance'
),
'emptyText' => '<div class="alert alert-info">No data found</div>',
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left visible-lg visible-md visible-sm">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row">
<div class="col-md-12">
{pager}
</div>
</div>',
'pager' => array('id'=>'_pagination',
'class' => 'LinkPager',
'header' => '', //remove pagination header
'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
),
));
also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class
if (!empty($_GET['sort']))
{
echo $_GET['Store_sort'] = $_GET['sort'];
}
UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either
http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list
I have breadcrumbs such as Home > Instance > Action in all my view pages. How can I remove the 'Home' link from all the breadcrumbs?
$this->breadcrumbs=array(
'Keypairs'=>array('admin'),
'Manage',
);
This can be done by setting the homeLink property to false, in your CBreadcrumbs widget initialization. This is usually done in a layout file.
In the default Yii app, in protected/views/layouts/main.php:
<?php if(isset($this->breadcrumbs)):?>
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
'homeLink'=>false // add this line
)); ?><!-- breadcrumbs -->
<?php endif?>
in layouts/main.php add 'homeLink' => false
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs'])? $this->params['breadcrumbs'] : [],
'homeLink' => false
]) ?>