Hellacool
Hellacool

Reputation: 1

yii framework Insert Contact Form in Home Page

i've have problem in understanding how can i render contact form created by default from Yii at the bottom of my Home Page.

What i can use? renderPartial() or simply render() and what is the right way to do this?

<?php $this->renderPartial('contact', array('model'=>$model)); ?> return me error of undefined value $model.

I'm new on Yii Framework someone can help me?

TIA


Now i have problems building contact Portlet

This is my component ContactForm.php

<?php
   Yii::import('zii.widgets.CPortlet');
   class ContactForm extends CPortlet
   {
      public $title="Contact Us";

      protected function  renderContent() {

        $form = new ContactForm;
           if(isset ($_POST['ContactForm']))
            {
            $form->attributes=$_POST['ContactForm'];
            if($form->validate())
                $this->controller->refresh ();
        }
        $this->render('contactForm', array('form'=>$form));
        }
   }

And this is my contacForm.php view that give me error:

   <?php echo CHtml::beginForm(); ?>
   <div class="row">
   <?php echo CHtml::activeLabel($form,'name'); ?>
   <br/>
   <?php echo CHtml::activeTextField($form,'name') ?>
   <?php echo CHtml::error($form,'name'); ?>  
   </div>
   <div class="row">
   <?php echo CHtml::submitButton('Submit'); ?>
   </div>
   <?php echo CHtml::endForm(); ?>

   CException

    ContactForm and its behaviors do not have a method or closure named "getAttributeLabel".

This is the part of SiteController where there is the contact function:

    /**
 * Displays the contact page
 */
public function actionContact()
{
    $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('contact',array('model'=>$model));
}

Where is the error?

Upvotes: 0

Views: 3730

Answers (1)

Narretz
Narretz

Reputation: 4993

Looks like a use case for a portlet. Here is a tutorial for creating a User-login portlet; with the contact form, it should be similar:

http://www.yiiframework.com/doc/blog/1.0/en/portlet.login

Upvotes: 1

Related Questions