Moving Default Contact form to index.php

I’m trying to move the yii generated contact form to index.php. I pretty much copy and pasted the code from the contact.php view file to index.php and added the action parameter to the active form widget. When I try to run the site it says $model is undefined. What am I missing? Or is there a better or different way to approach this?


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'contact-form',

        'action'=>'site/contact',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


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


     

	

in the controller, model variable is passed to the view in the contact action, like




$this->render('contact',array('model'=>$model));



what you need to do is to do the same on the index action

I think it got it to work by moving the actionContact method code into actionIndex. This should work if I remove the action parameter from the active form widget, right? Or do I need to change the action parameter to ‘site/index’




public function actionIndex()

	{

	// renders the view file 'protected/views/site/index.php'

	// using the default layout 'protected/views/layouts/main.php'

	

        $model=new ContactForm;

        if(isset($_POST['ContactForm']))

        {

            $model->attributes=$_POST['ContactForm'];

            if($model->validate())

            {

                $headers="From: {$model->email}\r\nReply-To: {$model->email}";

                mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);

                Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');

                $this->refresh();

            }

        }

        

        $this->render('index', array('model'=>$model));

	}



yep, both ways should work

Cheers

Gustavo

thanks for the help.