guys this the code I am using to make a ajax request, its not the complete code just relevant stuff
<div class="container whiteFont">
<label>New Tag</label>
<?php echo $this->Form->input('tagValue'); ?>
<input id="tag-button" type="button" value="Add Tag"/>
<div id=tag></div>
<?php
//on button click sands request to controller and displays response data in chosen field
$this->Js->get('#tag-button')->event(
'click',
$this->Js->request(
array('controller' => 'tags', 'action' => 'add',(Here need help),$this->Form->value('Post.id')),
array(
'update' => '#tag',
'async' => true,
)
)
);
?>
Now the problem is, my actions takes in two parameters.
I can set the second one which is Post.id
but I am not able to get the value of text field which has id of 'tagValue'.
I have tried using just html input fields as well.
When I try to use Js->get here it doesnt work as well.
help me out please.
Thank you
$this->Js->get('#tag-button')->event(
'click',
$this->Js->request(
array('controller' => 'tags', 'action' => 'add',(Here need help),$this->Form->value('Post.id')),
array(
'update' => '#tag',
'async' => true,
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'Post.id' => 1
))
use dataExpression and data to send parameters.
For more info: http://book.cakephp.org/2.0/en/views.html
Proper way to get all your form parameters passed:
$this->Js->get('#tag-button')->event(
'click',
$this->Js->request(
array('controller' => 'tags', 'action' => 'add',(Here need help),$this->Form->value('Post.id')),
array(
'update' => '#tag',
'async' => true,
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true
))
))
Related
$user
id
name
001
user 1
002
User 2
<ul>
<?php foreach($user as $user( { ?>
<input class="is-selected" type="checkbox" value="<?= $value->user->id ?>" />
<?php } ?>
</ul>
<button type="submit" class="btn is-primary">Send Reminder</button>
I'm using YII2, I'm displaying a list of inactive users. I'm using the checkbox to select the user. I'm going to send an email to the user I tagged.
how can i get id value from that checkbox and send data to controller?
I try to use javascript/jquery but i can't solved yet, i need some help from you guys
The above screenshot and your implementation is like you are talking 2 different things.
You would just be required a Grid View with CheckboxColumn
<?php
use yii\bootstrap\ActiveForm;
use yii\grid\GridView;
use yii\helpers\Html;
$form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'id' => 'user_form',
'options' => ['class' => 'lfp-listing']
]);
echo Html::submitButton('Send Reminder', ['class' => 'btn is-primary', 'name' => 'action', 'value' => 'send_reminder']);
echo GridView::widget([
'dataProvider' => $dataprovider,
'columns' => [
'id',
'name',
'email',
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' =>
function ($model) {
return ['value' => $model->id, 'class' => '', 'id' => 'checkbox'];
}
],
]
]);
ActiveForm::end();
Considering your Action is actionIndex()
public function actionIndex()
{
if (isset($_REQUEST['action']) && isset($_REQUEST['selection']) && 'send_reminder' == $_REQUEST['action'] ) {
foreach ($_REQUEST['selection'] as $userIds) {
//write down the email code here....
}
}
I am trying to get the IDs of all the selected check boxes in yii using JAVASCRIPT. Now i am able to get only the first element ID. Can anyone please suggest the correct code to get all the check box ID.
My View:
<input type="button" value="Multiple Host Date Entries" onclick="act();" />
<div id="grid"></div>
<?php
//zii.widgets.grid.CGridView bootstrap.widgets.TbExtendedGridView
$obj=$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'host_grid',
'dataProvider'=>$dataProvider,
'type' => 'striped bordered',
//'filter' => $model,
//'type' => 'striped bordered condensed',
//'summaryText' => false,
////'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array(
'id' => 'selectedIds',
'class' => 'CCheckBoxColumn',
'selectableRows'=>2,
'value' => '$data->host_id',
'checkBoxHtmlOptions' => array('name' => 'idList[]'),
),
array( // display 'create_time' using an expression
'name'=>'host_name',
'value'=>'$data->host_name',
),
array(
'name'=>'host_serviceid',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'status',
'value'=>'$data->status',
),
array(
'class'=>'CButtonColumn',
'template'=>'{edit_date}{update}{delete}',
'htmlOptions'=>array('width'=>'95px'),
'buttons' => array(
'update'=> array(
'label' => 'Update',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/a.png',
),
'delete'=> array(
'label' => 'Delete',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/d.png',
),
'edit_date' => array( //the name {reply} must be same
'label' => 'Add Date', // text label of the button
'url' => 'Yii::app()->createAbsoluteUrl("NimsoftHostsDetails/View", array("id"=>$data->host_id))', //Your URL According to your wish
'imageUrl' => Yii::app()->baseUrl.'/images/icons/m.png', // image URL of the button. If not set or false, a text link is used, The image must be 16X16 pixels
),
),)
),
))
;
?>
I must select some check boxes and click on multiple host date entries button to go to the specific controller.
My JavaScript:
function act()
{
var idList=$("input[type=checkbox]:checked").serializeArray();
var jsonStr = JSON.stringify(idList);
/* Object.keys(idList).forEach(function(key) {
console.log(key, idList[key]);
alert(idList[key]);
});*/
var a=$("input[type=checkbox]:checked").val();
alert(a);
if(idList!="")
{
if(confirm("Add Dates for multiple hosts?"))
{
var url='<?php echo $this->createUrl('Nimsoft/Date_all',array('idList'=>'val_idList')); ?>';
url=url.replace('val_idList',jsonStr);
//url=url.replace('val_idList',json_encode(idList));
//alert(url);
window.open(url);
/*$.post('Date_all',idList,function(response)
{
$.fn.yiiGridView.update("host_grid");
});*/
}
}
else
{
alert("Please Select atleast one host");
}
}
I need to pass the IDs to NIMSOFT controller so that I can have a for loop to process each one of those.
you can retrieve the checked column in client side (javasctipt):
var idArray = $(gridID).yiiGridView('getChecked', columnID);
// or
$.fn.yiiGridView.getSelection(gridID);
For all checked row ids we use this
var id = $.fn.yiiGridView.getChecked("your-grid-id", "selectedIds"); // array of seleted id's from grid
since three hours I don't found the error in jquery.
I try to refresh a div, after I've created a file
Here is my View
<?php
echo CHtml::ajaxLink('Neuen Export erstellen',
Yii::app()->createUrl('exporter/create' ),
array(
'data' => array(),
'dataType' => 'json',
'type' => 'POST',
'complete' => "js:function(html){
$('#export-grid').fadeOut().fadeIn();
}",
'success' => "js:function(html){
$('#export-grid').replaceWith();
}"
),
array(
'class' => 'c2a_gray alignright',
'style' => 'font-size: 12px',
)
);
?>
** My Controller **
public function actionCreate()
{
// createfile();...
// do some stuff
$this->renderPartial('//users//exporter//_tmo', true, true);
}
complete Option works in ajaxLink function very well
but if I put alert(html) inside complete I got "Object object"
I don't know how to update export-grid with the new content.
please help me!
thx!
Yes if you try to alert html then it will return Object.
Please try alert(html.responseText).
I have a form with select input. I want to auto submit the form when the dropdown list was selected.
My code:
<?php echo $this->Form->create('Product', array('controller'=>'products', 'action'=>'shipping_area'));
echo $this->Form->input('area', array('options' => array('1' => 'Within Malaysia', '2' => 'International'), 'empty' => 'choose area',
'label' => 'Choose shipping area', 'onChange'=>'javascript:this.form.submit()'));
//echo $this->Form->end('Save');
?>
I put 'onChange'=>'javascript:this.form.submit()', but it goes to http://localhost/cake/cake/products/shipping_area ( supposely http://localhost/cake/products/shipping_area )
I also tried 'onChange'=>'this.form.submit()', but got same error.
can anyone please help.
You can add an "id" attribute to the form and then every time that you get an "onchange" event in the "select" element, you have to obtain the "id" value and pass it to the javascript function "document.getElement('idValueHere')" and call to the fuction submit. More clearly, the following code:
<?php
# step 1: add an id attribute ('id' => 'anyFormName') to the array options
# step 2: add an onchange envent to the dropdown ('onChange'=>'document.getElementById("anyFormName").submit();')
echo $this->Form->create('Product', array('controller'=>'products', 'action'=>'shipping_area', 'id' => 'anyFormName'));
echo $this->Form->input('area', array('options' => array('1' => 'Within Malaysia', '2' => 'International'), 'empty' => 'choose area',
'label' => 'Choose shipping area', 'onChange'=>'document.getElementById("anyFormName").submit();'));
//echo $this->Form->end('Save');?>
Hope it helps you.
echo $this->Form->create('Product', array(
'url' => array(
'controller'=>'products', 'action'=>'shipping_area'
)
));
I'm trying to send some data to my controller with the Js helper like so:
view:
<?php
$this->Js->get('#FieldId')->event( //fieldId is a selectbox
'change',
$js->request(
array(
'controller'=>'users',
'action'=>'check'
),
array(
'update'=>'#result',
'data'=>'what should I put in here?'
)
)
);
?>
What should I put in data to send the value of the selected item of #fieldId and how can I us this data in my controller. The CakePHP documentation 'book' doesn't really explain much, and I'm not an expert either...
I found out that additional variables should be passed in that manner:
'data' => 'variableName=value'
So in the controller there is:
$this->params['form']['variableName']
There is also the possibility to eval some javascript values in 'data' but you have to set 'dataExpression' to true in the option array before.
I think this will help you.
<?php
$this->Js->get('#FieldId')->event('change', $this->Js->request(array(
'controller' => 'users',
'action' => 'check/DataName(view name)'
), array(
'update' => '#result',
'async' => true,
'method' => 'post',
'dataExpression' => true,
'data' => $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true,
)),
)) );
?>