Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Update a field based on the submit button - Yii
    primarykey
    data
    text
    <p>I'm new to Yii framework. I have to create three buttons in my form (update.php). i.e. (Save, Approve, Reject). I'm using the following fields in my form.</p> <pre><code>&lt;?php /* @var $this MessageTemplateController */ /* @var $model MessageTemplate */ /* @var $form CActiveForm */ ?&gt; &lt;div class="form"&gt; &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'message-template-form', 'enableAjaxValidation'=&gt;false, )); ?&gt; &lt;?php echo $form-&gt;errorSummary($model); ?&gt; &lt;div class="row"&gt; &lt;?php //$model-&gt;ReviewedDate=date('Y-m-d H:i:s');?&gt; &lt;?php echo $form-&gt;labelEx($model,'ReviewedDate'); ?&gt; &lt;?php echo $form-&gt;textField($model,'ReviewedDate',array('value'=&gt;'0000-00-00 00:00:00','readonly' =&gt; true)); ?&gt; &lt;?php echo $form-&gt;error($model,'ReviewedDate'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'SmsText'); ?&gt; &lt;?php echo $form-&gt;textArea($model,'SmsText',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt; &lt;?php echo $form-&gt;error($model,'SmsText'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'UpdatedDate'); ?&gt; &lt;?php echo $form-&gt;textField($model,'UpdatedDate'); ?&gt; &lt;?php echo $form-&gt;error($model,'UpdatedDate',array('value'=&gt;date('Y-m-d H:i:s'),'readonly' =&gt; true)); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'Approved'); ?&gt; &lt;?php echo $form-&gt;hiddenField($model, 'Approved'); ?&gt; &lt;?php echo $form-&gt;error($model,'Approved'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model_al, 'username'); ?&gt; &lt;?php $identity=Yii::app()-&gt;user-&gt;name;?&gt; &lt;?php echo $form-&gt;textField($model_al, 'username',array('value'=&gt;$identity,'readonly' =&gt; true), array('size' =&gt; 60, 'maxlength' =&gt; 250)); ?&gt; &lt;?php echo $form-&gt;error($model_al, 'username'); ?&gt; &lt;div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model_al, 'updatedtime'); ?&gt; &lt;?php echo $form-&gt;textField($model_al, 'updatedtime',array('value'=&gt;date('Y-m-d H:i:s'),'readonly' =&gt; true), array('size' =&gt; 60, 'maxlength' =&gt; 250)); ?&gt; &lt;?php echo $form-&gt;error($model_al, 'updatedtime'); ?&gt; &lt;div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model_al, 'comments on approval/rejection'); ?&gt; &lt;?php echo $form-&gt;textField($model_al, 'comments',array('size' =&gt; 60, 'maxlength' =&gt; 250)); ?&gt; &lt;?php echo $form-&gt;error($model_al, 'comments'); ?&gt; &lt;div&gt; &lt;div class="row buttons"&gt; &lt;?php echo CHtml::submitButton('Save', array('name' =&gt; 'save')); ?&gt; &lt;? echo '&amp;nbsp;&amp;nbsp;&amp;nbsp;'; ?&gt; &lt;?php echo CHtml::submitButton('Accept', array('name' =&gt; 'accept')); ?&gt; &lt;? echo '&amp;nbsp;&amp;nbsp;&amp;nbsp;'; ?&gt; &lt;?php echo CHtml::submitButton('Reject', array('name' =&gt; 'reject')); ?&gt; &lt;/div&gt; &lt;?php $this-&gt;endWidget(); ?&gt; &lt;/div&gt;&lt;!-- form --&gt; </code></pre> <p>Now I have created three buttons.There is a field called <strong><code>approved</code></strong> in the above form. I want this actions to happen when i click on the following buttons :<br> 1. <code>Save - All fields have to be saved but not approved(keep it as default).</code><br> 2. <code>Accept - All fields have to be saved with Approved changing to 1 in database.</code><br> 3. <code>Reject - All fields have to be saved with Approved changing to 0 in database.</code> </p> <p>How can I do this.</p> <p><strong>EDit</strong> I have added the following in my controller.</p> <pre><code>public function actionUpdate($id) { $model_mt=new Messagesintable; $model_al=new AuditLogin; $model=$this-&gt;loadModel($id); // Uncomment the following line if AJAX validation is needed // $this-&gt;performAjaxValidation($model); if(isset($_POST['MessageTemplate']) &amp;&amp; isset($_POST['AuditLogin'])) { $model-&gt;attributes=$_POST['MessageTemplate']; list($name,$mobile,$email)=retrieve_persondetails($id); if($model-&gt;save()) { $model_al-&gt;attributes=$_POST['AuditLogin']; if ($model_al-&gt;save()) $this-&gt;redirect(array('admin','id'=&gt;$model-&gt;Id)); } } $this-&gt;render('update',array( 'model'=&gt;$model, )); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload