使用submitButton打开一个对话框,即将'CActiveForm'改为对话框:yii

时间:2015-12-01 10:15:47

标签: yii dialog submit-button

我在视图表单中使用了submitButton,点击按钮我必须打开一个对话框,即另一个视图表单。我怎样才能做到这一点?     我的提交按钮代码是:

<?php
echo CHtml::submitButton('Mail to Client' ,array(
 'onclick'=>'js:act()',
'id'=>'$model->marketing_id','name' => 'ApproveButton' ,'class'=>'btn btn-success'));?>

从javascript方法act()我已经调用了我的控制器。这个按钮在我的管理员表单中。调用另一个视图的控制器代码是:

$this->render('_compose',array('mailList'=>$mailList,'model'=>$model),FALSE,true);

这个_compose视图,我必须以对话框形式打开。我的_Compose表单代码为:

<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
    'id'=>'mydialog',
    'options'=>array(
        'title'=>'Mail to client',
        'autoOpen'=>true,
    ),
));
?>

<div class="form wide">

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

    <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'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
        <?php echo $form->error($model,'email_to'); ?>
    </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 class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Send' : 'Send',array('class' => 'btn')); ?>
    </div>

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

</div>
 <?php $this->endWidget('zii.widgets.jui.CJuiDialog');
 echo CHtml::link('Open Dialog', '#', array(
   'onclick'=>'$("#mydialog").dialog("open"); return false;',
));?>

1 个答案:

答案 0 :(得分:0)

您可以使用CJuiDialog

$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
    'id'=>'mydialog',
    'options'=>array(
        'title'=>'Mail to client',
        'autoOpen'=>false,
    ),
));

<div class="form wide">

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

    <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'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
        <?php echo $form->error($model,'email_to'); ?>
    </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 class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Send' : 'Send',array('class' => 'btn')); ?>
    </div>

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

</div>

$this->endWidget('zii.widgets.jui.CJuiDialog');
/** End Widget **/
echo CHtml::link('Open Dialog', '#', array(
   'onclick'=>'$("#mydialog").dialog("open"); return false;',
));