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;
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));
}
I’m still confused, how can sent to the Site Controller controller, when user enter the data from contact form?
Do you mean, how can the SiteController knows what data were entered by the user in the contact form?
It happens in this line:
$model->attributes=$_POST['ContactForm'];
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.
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/