Contact Form action

In default YII program generator, contact form generated by YII. So I want to change when submit button click save data to database not send to email.

I created table to saving information of contact, hire the table information:

T_msg: id, name, title,email, subject, content

I get function to processing data when submit button clicked.

$model=new ContactForm;






				//$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.');






I’m still confused, how can sent to the Site Controller controller, when user enter the data from contact form?

Thanks you

Hi Hermans,

Do you mean, how can the SiteController knows what data were entered by the user in the contact form?

It happens in this line:


Take a look at the page source of the Contact page, you should see the name of the fields there like ContactForm[name],ContactForm[email], etc. Simply put, $model->name will be equal to the value of ContactForm[name], and so on. Then it is being validated, and sends the email if validation passed.

thank you, very helpful

what SiteController should be there in Yii ? I see that the login and contact in working on this controller

Hi Hermans,

I’m not sure if I got your question correctly…would you mind rephrasing your question? I just would like to give you accurate answer. :)

Previously I thought that SiteController it should be in every website built with Yii.

however, after I know about the search for Site Controller is the controller name.

For example:


the site Controller is SiteController

and contact is Action in SiteController ->actionContact


above code, call contact view at ‘views->site->contact.php’

how if ‘contact.php’ is placed in ‘views->contact->contact.php’ ??

Then you should render page like this:


I haven’t tested this code, inform me if this doesn’t work. As you might have noticed, the first parameter calls the appropriate ‘view’ file, and what we did was just to point it to our desired ‘view’ file (contact.php), which is located under /views/contact/

thank you :)

No problem :)