Hi all!
I’m trying to make a simple contact form, what I want is that when someone sends a email, after successful validation, the user stays on the same page, and not redirected. I tried the following code, but after the validation the fields of the form are filled with previous input values.
public function actionContacts(){
$mdlContact = new ContactForm();
if (isset($_POST['ContactForm'])) {
$mdlContact->attributes = $_POST['ContactForm'];
if ($mdlContact->validate()){
Yii::app()->user->setFlash('success',"Email sent!");
}
}
$this->render('contacts', array(
'mdlContact'=>$mdlContact));
}
So I tried this
public function actionContacts(){
$mdlContact = new ContactForm();
if (isset($_POST['ContactForm'])) {
$mdlContact->attributes = $_POST['ContactForm'];
if ($mdlContact->validate()){
Yii::app()->user->setFlash('success',"Email sent!");
]$this->redirect('contacts');//Here I redirect for the same action
}
}
$this->render('contacts', array(
'mdlContact'=>$mdlContact));
}
And it works but doesn’t seem very logical or the correct way of doing it, can someone please advise me, how to achieve this.
Thanks