I have a contact form that I want to display it in different sections of my website, but I don’t know how to reuse same contact form (model, view, controller).
I defined 3 models: section1Model, section2Model, contactFormModel and 3 controllers (secion1Controller, section2Controller, contactFormController).
So, I have the following links: /section1/index and /section2/index and i want to add the contact form at the bottom of each of this pages.
First time I was thinking i can use a widget but the widget has no actions.
Thank you Zaccaria! Based on your suggestion I made a widget like this:
class ContactFormWidget extends CWidget {
public function run() {
$scenario = $this->getController()->id;
$model = new ContactForm($scenario);
if(isset($_POST['ContactForm'])) {
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
/*
php code for actions
.......
*/
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->getController()->refresh();
}
}
$this->render('contactFormWidget',array('model'=>$model));
}
}