Beispiel #1
0
 public function renderForm()
 {
     // Form and Fields
     $this->form = FormService::findBySlug($this->slug);
     if (isset($this->form) && $this->form->active) {
         // fields and html
         $fieldsHtml = FormUtil::getApixFieldsHtml($this->form, ['label' => $this->showLabel]);
         $captchaHtml = null;
         // Views Path
         $formPath = "{$this->template}/form";
         $captchaPath = "{$this->template}/captcha";
         // submit url
         if (!isset($this->ajaxUrl)) {
             $formSlug = $this->form->slug;
             $this->ajaxUrl = Url::toRoute(["/apix/form/{$formSlug}"], true);
         }
         if ($this->form->captcha) {
             $captchaHtml = $this->render($captchaPath);
         }
         $formHtml = $this->render($formPath, ['fieldsHtml' => $fieldsHtml, 'captchaHtml' => $captchaHtml]);
         $this->options['action'] = $this->ajaxUrl;
         $this->options['method'] = 'post';
         $this->options['cmt-controller'] = 'form';
         $this->options['cmt-action'] = 'generic';
         if (!isset($this->options['class'])) {
             $this->options['class'] = 'cmt-form';
         }
         if (!isset($this->options['id'])) {
             $this->options['id'] = "frm-{$this->slug}";
         }
         if (isset($this->cmtController)) {
             $this->options['cmt-controller'] = $this->cmtController;
         }
         if (isset($this->cmtAction)) {
             $this->options['cmt-action'] = $this->cmtAction;
         }
         return Html::tag('form', $formHtml, $this->options);
     } else {
         echo "<div class='warning'>Form not found or submission is disabled by site admin.</div>";
     }
 }