Hey guys,
what I want to do, is create a commenting function, where the user can submit a comment (which will be saved in database with a "pending" status at first). After that a lightbox (colorbox plugin) should pop up with further input fields (such as username and email address). In the lightbox content (seperate file) I need the id of the before created comment.
The form for the comment looks like that at the moment:
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'comment-form' . $entry->entry_id,
// 'enableAjaxValidation' => true,
'enableClientValidation' => true,
));
?>
<?php
//Create an instance of ColorBox
$colorbox = $this->widget('application.extensions.colorpowered.JColorBox');
$colorbox
->addInstance('#comment_dialog_box' . $entry->entry_id, array('width' => "390px", 'inline' => true, 'href' => "#comment_dialog" . $entry->entry_id, 'transition' => 'elastic', 'speed' => 100));
?>
<div id="comment_dialog_box<?php echo $entry->entry_id; ?>"></div>
<?php echo $form->errorSummary($model); ?>
<div class="row" class="input_field">
<span style="font-size:20px; color:#000; float:left; margin:10px 5px 0 0;">Wie sehen Sie das? </span>
<span style="float:right;" onFocus="setFocus()">
<?php echo $form->textArea(Translation::model(), 'content', array('rows' => 1, 'cols' => 50, 'class' => 'input_focus', 'id' => 'comment_textArea' . $entry->entry_id)); ?>
<?php echo $form->error(Translation::model(), 'content'); ?>
</span>
<div style="clear:left; clear:right;"></div>
</div>
<div class="row buttons input_buttons" style="float:right;">
<?php echo CHtml::activeHiddenField($entry, 'entry_id'); ?>
<?php
echo CHtml::ajaxSubmitButton('Posten', 'comment/create'); ?>
</div>
<div style="clear:right;"></div>
<?php $this->endWidget(); ?>
</div><!-- form -->
The lightbox content looks like this:
<script type="text/javascript">
$(document).ready(function() {
$("#comment_dialog_box<?php echo $entry->entry_id; ?>").colorbox({open:true});
}
</script>
<div id="comment_dialog<? echo $entry->entry_id; ?>" title="" style="color:#fff;">
<?php
$colorbox = $this->widget('application.extensions.colorpowered.JColorBox');
$colorbox
->addInstance('#comment_dialog_box' . $entry->entry_id, array('width' => "390px", 'inline' => true, 'href' => "#comment_dialog" . $entry->entry_id, 'transition' => 'elastic', 'speed' => 100));
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'comment-colorbox' . $entry->entry_id,
'enableAjaxValidation' => true,
'enableClientValidation' => true,
));
?>
<span style="font-size:40px; color:#fff;"><b>Start</b>regie Gast</span><br/><br/>
<?php echo $form->errorSummary($model); ?>
<input name="Comment[comment_id]" type="hidden" id="comment_dialog_textArea<? echo $entry->entry_id; ?>" value="<?php //echo 127; ?>" />
<div class="row">
<?php echo $form->textField($model, 'email', array('size' => 50, 'maxlength' => 256, 'value' => 'E-Mail Adresse...', 'class' => 'input_focus input_help')); ?>
<?php echo $form->error($model, 'email'); ?>
</div>
<div class="row">
<?php echo $form->textField($model, 'autor', array('size' => 50, 'maxlength' => 256, 'value' => 'Vorname...', 'class' => 'input_focus input_help')); ?>
<?php echo $form->error($model, 'autor'); ?>
</div>
<br/>
<p style="float:left; width:80%;">Bitte beachten Sie, dass Ihre Namensangabe öffentlich sichtbar ist. Die Angabe Ihrer Emailadresse dient der Vorbeugung gegen Spam und ist zu keinem Zeitpunkt öffentlich zugänglich.</p>
<?php echo CHtml::ajaxSubmitButton('ok', 'comment/update', '', array('style' => 'float:left', 'style' => 'bottom:0px')); ?>
<?php $this->endWidget(); ?>
</div>
The actionCreate in the comment controller looks as follows:
public function actionCreate()
{
if (isset(/* $_POST['Comment'], */ $_POST['Translation'])) {
$model = new Comment;
$translation = new Translation;
$this->performAjaxValidation($model);
$this->performAjaxValidation($translation);
// populate input data to $model and $translation
$translation->attributes = $_POST['Translation'];
$translation->language_code = 'de';
$valid = $translation->validate(); // && $valid ;
if ($valid) {
$entry = Entry::model()->findByPk($_POST['Entry']['entry_id']);
if ($entry->addComment($model, $translation, $entry)) {
$this->redirect(array('colorbox'), array(
'entry' => $entry,
'model' => $model,
));
}}}
So my two questions / problems are:
1.) how is it possible, to pass the comment object (or the comment id) of the in the beginning created comment to the afterwards opened lightbox (to know which comment to update)
- I just can’t figure out, how to open the colorbox as a “return” value of the actionCreate. I’m not really a js master so … would be awesome, if someon recognizes the mistake(s) I made?!
Thanks in advance,
Mayjestic