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?
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));
}