打开对话框的问题:Yii

时间:2015-11-20 07:00:49

标签: yii dialog

我在我的表单中使用了ajaxSubmitButton。单击按钮我试图打开对话框当我单击按钮时,对话框打开并显示为该表单编写的整个代码。如何解决这个问题?

我的按钮代码是:

<div class="btnalign" style="margin-top: 20px;margin-left:20px;">

    <?=CHtml::ajaxSubmitButton('Mail to Client', Yii::app()->createUrl('reply/composeMail'),
        array('type'=>'POST',
              'data'=> 'js:{"data1":callData()}',
            //'success' => 'function(response){afterSubmitForm(response);}'
              'success'=>'js:function(string){ alert(string);$.fn.yiiGridView.update("my-grid"); }'
        ),

        array('class' => 'btn btn-primary'));
    ?>

</div>
  

我的控制器代码:

public function actionComposeMail()
{
if(Yii::app()->request->isAjaxRequest){ 
    print_r($_POST['data1']);
        if(isset($_POST['data1'])){
            $model=new Reply;
            $model->scenario = 'compose';

            EQuickDlgs::render('_compose',array(
            'model'=>$model,
            ));
            }else{
            echo "Please select row to Mail.";
        }
    }
    else
    {
        echo "The request is invalid.";
    }
}
  

我的对话框表单代码是:

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'reply-form',
    'enableAjaxValidation'=>true,
'htmlOptions' => array('enctype' => 'multipart/form-data'), 
 )); ?>

<p class="note">Fields with <span class="required">*</span> are required.For multiple recipients please seperate by comma</p>

<?php echo $form->errorSummary($model); ?>



<div class="row col2">
    <?php echo $form->labelEx($model,'email_from'); ?>
    <?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
    <?php echo $form->error($model,'email_from'); ?>
</div>

<div class="row col2">
    <?php echo $form->labelEx($model,'email_to'); ?>
    <?php echo $form->textField($model,'email_to',array('size'=>60,'maxlength'=>150)); ?>
    <?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>

<div class="row col2">
    <?php echo $form->labelEx($model,'email_cc'); ?>
    <?php echo $form->textField($model,'email_cc',array('size'=>60,'maxlength'=>250)); ?>
    <?php echo $form->error($model,'email_cc'); ?>
</div>

<div class="row col2">
    <?php echo $form->labelEx($model,'subject'); ?>
    <?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>250)); ?>
    <?php echo $form->error($model,'subject'); ?>
</div>
<div style="clear:both"></div>

<div class="row">
    <?php echo $form->labelEx($model,'message'); ?>
    <?php echo $form->textArea($model,'message',array('rows'=>6, 'cols'=>50)); ?>
    <?php echo $form->error($model,'message'); ?>
</div>

<div style="clear:both"></div>

<div style="clear:both"></div>
<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Send' :         'Send',array('class' => 'btn')); ?>
  </div>

<?php $this->endWidget(); ?>

  

对话图像

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须使用renderPartial()代替render(),并尝试在邮件表单视图的末尾调用Yii::app()->end()

public function actionComposeMail()
{
if(Yii::app()->request->isAjaxRequest){ 
    print_r($_POST['data1']);
        if(isset($_POST['data1'])){
            $model=new Reply;
            $model->scenario = 'compose';

            $this->renderPartial('_compose',array(
            'model'=>$model,
            ));
            }else{
            echo "Please select row to Mail.";
        }
    }
    else
    {
        echo "The request is invalid.";
    }
}