Passing combobox selected value to a dialog using ajaxlink - php

I' trying to pass the dropDownList selected value to this Dialog.
Any ideas on how I can do this?
I tried adding another parameter to the ajaxlink, using array('id'=>'showEventoDialog','tipoaux'=>$data["tipo"]), or only $data->tipo but can't seem to do what I want.
I'm also trying to get the value via $_GET from the Dialog form.
Here's my form and the Dialog link within the form
<?php echo $form->labelEx($model,'tipo'); ?>
<?php echo $form->dropDownList($model,'tipo',Lookup::items('Teste')); ?>
<?php echo $form->error($model,'tipo'); ?>
...
<?php echo $form->labelEx($model,'eventoid'); ?>
<div id="evento">
<?php echo $form->dropDownList($model,'eventoid',CHtml::listData(Evento::model()->findAll(),'id', 'designacao'),array('prompt'=>'Escolha','class'=>'required')); ?>
<?php echo CHtml::ajaxLink(Yii::t('evento','Novo Evento'),$this->createUrl('evento/addnewcom'),array(
'onclick'=>'$("#eventoDialog").dialog("open"); return false;',
'update'=>'#eventoDialog'
),array('id'=>'showEventoDialog'));?>
<div id="eventoDialog"></div>
</div>
Any ideas on how to do this?
Plus will the solution work with any other type of value, like textfield or something else on my form, so I can pass the values to dialogs BEFORE the parent form is submitted.

You can hook up some code to the open event of the dialog that will fire right before the dialog appears. In this code you can query the selected option and write it to the dialog:
<?php echo $form->labelEx($model,'eventoid'); ?>
<div id="evento">
<?php echo $form->dropDownList($model,'eventoid',CHtml::listData(Evento::model()->findAll(),'id', 'designacao'),array('prompt'=>'Escolha','class'=>'required')); ?>
<?php echo CHtml::ajaxLink(Yii::t('evento','Novo Evento'),$this->createUrl('evento/addnewcom'),array(
'onclick'=>'$("#eventoDialog").dialog({open: function(){ $("#selectedvalue").text($("#eventoid").val()); }}) .dialog("open"); return false;',
'update'=>'#eventoDialog'
),array('id'=>'showEventoDialog'));?>
<div id="eventoDialog">
<span>Selected value: </span><span id="selectedvalue" />
</div>
</div>

Related

how to diplay page id for review php in div?

I tried several options but they are not working, I have 2 pages, page.php and rating.php, on page.php, I have button with this link
< a href=”rating.php/go.php?id=$rows[$id]”>button</a>
, but on page rating.php I have a div with code.
<div id="review" ><?php echo $rows['id'];?></div>
I want that the $rows[$id]from the link rating.php/go.php?id=$rows[$id] could be displayed on div like this . How can I do that to see this $rows[$id] on div?
On page.php you are using < a href="rating.php?id=$rows[$id]">button</a>
If you want $rows[$id] in your rating.php use $_GET
<div id="review" ><?php echo $_GET['id'];?></div>
Read this tutorials too http://www.tutorialspoint.com/php/php_get_post.htm
you get a param from an url with that code snippet:
<div id="review"><?php echo $_GET['id']; ?></div>
the $row[$id] must be a value, it can't be an object
works as :
<div id="review"><?php echo $_GET['id']; ?></div>
Read this:
http://www.formget.com/php-post-get/

How to create forms with multiple submit buttons

I'm new to Yii framework.I'm using the form.php to update the fields of the table. So now I use this form with three submit buttons - [Save, Accept, Reject]. The form now has the following fields.
<div class="row">
<?php //$model->ReviewedDate=date('Y-m-d H:i:s');?>
<?php echo $form->labelEx($model,'ReviewedDate'); ?>
<?php echo $form->textField($model,'ReviewedDate',array('value'=>'0000-00-00 00:00:00','readonly' => true));te ?>
<?php echo $form->error($model,'ReviewedDate'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Approved'); ?>
<?php echo $form->textField($model,'Approved'); ?>
<?php echo $form->error($model,'Approved'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('confirm' => 'Are you sure to save')); ?></div>
Above there is Approved field.Now, when I click on save all the other fields has to be updated except for approved. (Approved is 0 by default). So when I click on Approve button it should update Approved as well as other fields. When I click on Reject, it should update the approved field to 0. How can I do this.
You can use three submit button and can manage functionality as per that.
In the form create 3 buttons as per below :
<?php echo CHtml::submitButton('Save', array('name' => 'save')); ?>
<?php echo CHtml::submitButton('Accept', array('name' => 'accept')); ?>
<?php echo CHtml::submitButton('Reject', array('name' => 'reject')); ?>
In the controller check which button is clicked as per below :
<?php
if(isset($_POST['save'])){
//save submit button is click and code for save button will be here
}
if(isset($_POST['accept'])){
//accept submit button is click and code for accept button will be here
}
if(isset($_POST['reject'])){
//reject submit button is click and code for reject button will be here
} ?>
All the best :)
Instead of having 3 submit buttons, I'd suggest you use a dropdown list so your users can pick the desired action. Then you check for the value of the dropdown control in order to either "Save", "Accept" or "Reject".
echo CHtml::dropDownList('action', '', array('Accept', 'Reject'));
And in your controller:
if (isset($_POST['ModelName'])) {
switch ($_POST['action']) {
case 'Accept':
# code for Acceptance
break;
case 'Reject':
# code for Rejection
break;
}
//Continue with Saving the Model data here
}
You can add a hiddenField with the action:
<?php echo $form->hiddenField($model, 'typeSubmit'); ?> // Add 'typeSubmit' attribute on the model
And 3 submit buttons. Each button puts on the hidden field the type of Submit.
<?php echo CHtml::submitButton('Save', array('class'=>'btn','onclick'=>'$("#ModelName_typeSubmit").val("save");')); ?> // #ModelName = $model name class.
<?php echo CHtml::submitButton('Accept', array('class'=>'btn','onclick'=>'$("#ModelName_typeSubmit").val("accept");')); ?>
<?php echo CHtml::submitButton('Reject', array('class'=>'btn','onclick'=>'$("#ModelName_typeSubmit").val("reject");')); ?>

jquery toggle one div in php while loop

I have this While loop in my php code where I echo rows inside one div that acts like a button and when I press that "button" I want to hide/show the connected div with the jQuery function "toggle". I only get it to work so that when I click any of the "buttons" it opens all divs and not just that one that's connected.
<script>
$(document).ready(function(){
$(".scorec").click(function(){
$(".scorematcho").slideToggle('slow');
});
});
</script>
That's the jQuery I'm using at the moment.
<?php $RM = mysql_query("SELECT * FROM score ORDER BY ScoreID DESC LIMIT 3");
while ($ScoreD = mysql_fetch_assoc($RM)) {
$a = $ScoreD["ScoreOne"]; $b = $ScoreD["ScoreTwo"];?>
<div class="scorec" >
<?php if($a>$b){;?><font color="green"><?php }else{?><font color="red"><?php }?>
<div class="scorel"><img src="flags/<?php echo $ScoreD["FlagOne"]; ?>.png" style="float:left;">
<?php echo $ScoreD["TeamOne"]; ?> | <?php echo $ScoreD["ScoreOne"]; ?></div>
<div class="scorem">-</div>
<div class="scorer"><?php echo $ScoreD["ScoreTwo"]; ?> | <?php echo $ScoreD["TeamTwo"]; ?>
<img src="flags/<?php echo $ScoreD["FlagTwo"]; ?>.png" style="float:right;"></div></font>
</div>
<div class="scorematcho" >
<div class="scorematch">
de_dust2
16-2
</div>
<div class="scorematch">
de_nuke
16-2
</div>
<div class="scorematch">
de_dust
16-2
</div>
</div>
<?PHP } session_destroy()?>
That's the HTML/PHP I'm using. The div "scorec" is the "button" and "scorematcho" is the div I wan't to toggle.The text inside "scorematcho" shall be PHP also, just haven't changed it yet. I have searched and tested some things but can't get anything to work properly, I have noticed that some put all their PHP code inside an "echo", why is that and could that be the problem? Hope that's enough information, please tell if not. Also, if you have some other improvements you think I should make to the code, please tell.
I have added this jfiddle Hope it helps!! http://jsfiddle.net/H77yf/
$(".scorec").click(function(){
$(this).next().slideToggle('slow');
});

Is it possible to show the database values in jquery thickbox

In hiddenModalContent div is it possible to display the database value as once thickbox is opening it just showing nothing
<?php
foreach($this->list_details as $key=>$details)
{?>
<div class="sc_content_subheading"><? echo $this->escape($details['list_name'])?></div>
<div id="hiddenModalContent" style="display:none;">
<span class="content_subheading">List name </span><? echo $details['list_name'];?><br/>
</div>
<?php }?>
It seems all you are only outputting the list name. What else in the array would you like to show?

jQuery Tabs - jquery script only works for 1st tab - bad initialize?

I have jQuery Tabs in which each tab and corresponding content are populated by a PHP foreach loop.
For each tab the user can upload a picture. I have this setup in a way so that as soon as the user chooses a file, a jquery script makes the upload begin automatically -- and the browse button is hidden and replaced by "Uploading your picture".
Here is the code (CI markup):
<ul class="tab_header">
<?php foreach ($p as $row):
echo '<li>
' . $row->p_name . '
</li>';
endforeach; ?>
</ul>
<?php foreach ($p as $row): ?>
<div id="tabs-<?php echo $row->p_id; ?>">
<?php echo form_open_multipart('/p/p_upload_picture/' . $row->p_id, 'id="upload_form"');
echo form_upload('userfile', '', 'id="file_select"');
echo form_hidden('upload','upload');
echo form_close(); ?>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
</div>
<?php endforeach; ?>
<script>
$(function(){
$("#file_select").change(function(){
$("#upload_form").submit();
$("#upload_form_div").hide();
$("#loading").show();
});
});
</script>
This works perfectly but only on the first tab.
In all other tabs, the jquery script doesn't run -- as soon as I choose a file, the file name is shown in the browse button field instead, and no upload happens (form isn't submitted).
I wonder if this has to do with the script not being initialized for the other tabs.
How can I fix this?
Thanks for helping, much appreciated.
Your field has an id. Which should be unique per element.
jQuery only returns the first element it encounters with the given id, that's why your code isn't working. I would suggest adding a class instead of an id to your field.
$('.class-of-field')..change(function() {
..
});
The above should do the job.
This would be the equivalent code without jQuery:
var el = document.getElementById('file_select');
Which only returns one element, have a look at the documentation.

Categories