Yii Framework Forum: Ajax Contact Form - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Contact Form Rate Topic: -----

#1 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 11 May 2010 - 11:30 AM

I'm trying to convert the standard Yii Contact Form into an Ajax form. So basically if the submit button is pressed the whole page should not load.

I tried the following in the view and it did not work

<?php 

$form=$this->beginWidget('CActiveForm', array(
	 'id'=>'contact-form',
	'enableAjaxValidation'=>true,
));

?>


My controller looks as follows


public function actionContact()
	{
		$model=new ContactForm;
		$content = $model->getContactContent(2);
		
	
		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();
			}
			
		}
		if(Yii::app()->request->isAjaxRequest){
			$this->renderPartial('contact',array('model'=>$model,'content'=>$content));
		}else{
			$this->render('contact',array('model'=>$model,'content'=>$content));
		}
	}


What is the best approach to do this
0

#2 User is offline   james2010 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 19-February 10

Posted 13 May 2010 - 09:05 AM

http://www.yiiframew...rm/page__st__40

last post you will find the answer
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users