Private Messaging

Hie, I’m a first timer to Yii and was trying to implement the private messaging extension on my demo project.When it comes to the compose new message view, on the receiver input field I get an “Receiver cannot be blank” error even after it identifies a user from the database using the auto suggest jquery plugin.

Any help ideas please?

I think its not posting the value. check the POST !

The post code is in the controller below. I have also attached the view.

message/messageController

<?php

class ComposeController extends Controller

{

public &#036;defaultAction = 'compose';





public function actionCompose(&#036;id = null) {


	&#036;message = new Message();


	if (Yii::app()-&gt;request-&gt;getPost('Message')) {


		[b]&#036;receiverName = Yii::app()-&gt;request-&gt;getPost('receiver');[/b]


	    &#036;message-&gt;attributes = Yii::app()-&gt;request-&gt;getPost('Message');


		&#036;message-&gt;sender_id = Yii::app()-&gt;user-&gt;getId();


		if (&#036;message-&gt;save()) {


			Yii::app()-&gt;user-&gt;setFlash('messageModule', MessageModule::t('Message has been sent'));


		    &#036;this-&gt;redirect(&#036;this-&gt;createUrl('inbox/'));


		} 


                    else if (&#036;message-&gt;hasErrors('receiver_id')) {


			&#036;message-&gt;receiver_id = null;


			&#036;receiverName = '';


		}


	} else {


		if (&#036;id) {


			&#036;receiver = call_user_func(array(call_user_func(array(Yii::app()-&gt;getModule('message')-&gt;userModel, 'model')), 'findByPk'), &#036;id);


			if (&#036;receiver) {


				&#036;receiverName = call_user_func(array(&#036;receiver, Yii::app()-&gt;getModule('message')-&gt;getNameMethod));


				&#036;message-&gt;receiver_id = &#036;receiver-&gt;id;


			}


		}


	}


	&#036;this-&gt;render(Yii::app()-&gt;getModule('message')-&gt;viewPath . '/compose', array('model' =&gt; &#036;message, 'receiverName' =&gt; isset(&#036;receiverName) ? &#036;receiverName : null));


}

}

compose view

<?php $this->pageTitle = Yii::app()->name . ’ - ’ . MessageModule::t(“Compose Message”); ?>

<?php

$this->breadcrumbs = array(

MessageModule::t(&quot;Messages&quot;),


MessageModule::t(&quot;Compose&quot;),

);

?>

<?php $this->renderPartial(Yii::app()->getModule(‘message’)->viewPath . ‘/_navigation’); ?>

<h2><?php echo MessageModule::t(‘Compose New Message’); ?></h2>

<div class="form">

&lt;?php


&#036;form = &#036;this-&gt;beginWidget('CActiveForm', array(


    'id' =&gt; 'message-form',


    'enableAjaxValidation' =&gt; false,


        ));


?&gt;





&lt;p class=&quot;note&quot;&gt;&lt;?php echo MessageModule::t('Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.'); ?&gt;&lt;/p&gt;





    &lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;





&lt;div class=&quot;row&quot;&gt;


    &lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'receiver_id'); ?&gt;


    &lt;?php


    &#036;this-&gt;widget('zii.widgets.jui.CJuiAutoComplete', array(


        'name' =&gt; 'receiver',


        'model' =&gt; &#036;model,


        'value' =&gt; &quot;&#036;receiverName&quot;,


        'source' =&gt; &#036;this-&gt;createUrl('suggest/user'),


        // additional javascript options for the autocomplete plugin


        'options' =&gt; array(


            'showAnim' =&gt; 'fold',


            'select' =&gt; &quot;js: function(event, ui) {


                                     console.log(ui.item);


                                     &#036;('#PMessages_receiver_id').val(ui.item['id']);


                            }&quot;


        ),


    ));


    ?&gt;

<?php echo $form->hiddenField($model, ‘receiver_id’); ?>

<?php echo $form->error($model, ‘receiver_id’); ?>

&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


    &lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'subject'); ?&gt;

<?php echo $form->textField($model, ‘subject’); ?>

<?php echo $form->error($model, ‘subject’); ?>

&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


    &lt;?php echo &#036;form-&gt;labelEx(&#036;model, 'body'); ?&gt;

<?php echo $form->textArea($model, ‘body’); ?>

<?php echo $form->error($model, ‘body’); ?>

&lt;/div&gt;





&lt;div class=&quot;row buttons&quot;&gt;


&lt;?php echo CHtml::submitButton(MessageModule::t(&quot;Send&quot;)); ?&gt;


&lt;/div&gt;

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

</div>

<?php $this->renderPartial(Yii::app()->getModule(‘message’)->viewPath . ‘/_suggest’); ?>