public function actionIndex($slug)
 {
     $form = FormService::findBySlug($slug);
     $template = $form->template;
     $formFields = $form->getFieldsMap();
     $model = new GenericForm(['fields' => $formFields]);
     if ($form->captcha) {
         $model->setScenario('captcha');
     }
     if ($model->load(Yii::$app->request->post(), 'GenericForm') && $model->validate()) {
         // Save Model
         if (FormService::processForm($form, $model)) {
             // Trigger User Mail
             if ($form->userMail) {
                 Yii::$app->cmgFormsMailer->sendUserMail($form, $model);
             }
             // Trigger Admin Mail
             if ($form->adminMail) {
                 Yii::$app->cmgFormsMailer->sendAdminMail($form, $model);
             }
             // Trigger Ajax Success
             return AjaxUtil::generateSuccess($form->successMessage);
         }
     }
     // Generate Errors
     $errors = AjaxUtil::generateErrorMessage($model);
     // Trigger Ajax Failure
     return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors);
 }
 public function actionIndex($slug)
 {
     $form = FormService::findBySlug($slug);
     $template = $form->template;
     $formFields = $form->getFieldsMap();
     $model = new GenericForm(['fields' => $formFields]);
     if ($form->captcha) {
         $model->setScenario('captcha');
     }
     if ($model->load(Yii::$app->request->post(), 'GenericForm') && $model->validate()) {
         // Save Model
         if (FormService::processForm($form, $model)) {
             // Trigger User Mail
             if ($form->userMail) {
                 Yii::$app->cmgFormsMailer->sendUserMail($form, $model);
             }
             // Trigger Admin Mail
             if ($form->adminMail) {
                 Yii::$app->cmgFormsMailer->sendAdminMail($form, $model);
             }
             // Set success message
             if (isset($form->successMessage)) {
                 Yii::$app->session->setFlash('message', $form->successMessage);
             }
             // Refresh the Page
             return $this->refresh();
         }
     }
     if (isset($template)) {
         // Configure Layout
         if (isset($template->layout)) {
             $this->layout = "//{$template->layout}";
         }
         $view = $template->viewPath . "/{$template->frontendView}";
         if (isset($template->layout) && isset($view)) {
             return $this->render($view, ['form' => $form, 'model' => $model]);
         }
     }
     return $this->render(WebGlobalCore::PAGE_INDEX, ['model' => $model]);
 }