public function actionUpdate($type)
 {
     $settings = SiteService::getAttributeMapBySlugType(Yii::$app->cmgCore->getSiteSlug(), $type);
     $fieldsMap = FormUtil::fillFromModelAttribute("config-{$type}", $settings);
     $model = new GenericForm(['fields' => $fieldsMap]);
     if ($model->load(Yii::$app->request->post(), 'GenericForm') && $model->validate()) {
         $settings = FormUtil::getModelAttributes($model, $settings);
         ModelAttributeService::updateAll($settings);
         return $this->redirect("index?type={$type}");
     }
     return $this->render('update', ['model' => $model, 'type' => $type]);
 }
Beispiel #2
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>";
     }
 }
Beispiel #3
0
 public function renderForm()
 {
     if (isset($this->form) && $this->form->active) {
         $model = $this->model;
         $activeForm = $this->activeForm;
         $fieldsHtml = FormUtil::getFieldsHtml($activeForm, $this->model, ['label' => $this->showLabel]);
         echo $fieldsHtml;
         if ($this->form->captcha) {
             if ($this->showLabel) {
                 $captchaHtml = $activeForm->field($model, 'captcha')->widget(Captcha::classname(), ['options' => ['placeholder' => 'Captcha*']]);
             } else {
                 $captchaHtml = $activeForm->field($model, 'captcha')->label(false)->widget(Captcha::classname(), ['options' => ['placeholder' => 'Captcha*']]);
             }
             echo $captchaHtml;
         }
         if (!isset($this->formActions)) {
             echo "<div class='frm-actions'><input type='submit' value='Submit' /></div>";
         } else {
             echo $this->formActions;
         }
     } else {
         echo "<div class='warning'>Form submission is disabled by site admin.</div>";
     }
 }
Beispiel #4
0
use yii\helpers\Url;
use yii\widgets\ActiveForm;
// CMG Imports
use cmsgears\core\common\utilities\FormUtil;
include 'header.php';
?>
<section class="wrap-content container clearfix">
	<div class="cud-box">
		<h2>Update <?php 
echo ucfirst($type);
?>
 Settings</h2>
		<?php 
$form = ActiveForm::begin(['id' => 'frm-update-settings', 'options' => ['class' => 'frm-split']]);
?>

		<?php 
echo FormUtil::getFieldsHtml($form, $model);
?>

		<div class="box-filler"></div>
		<?php 
echo Html::a("Back", ["index?type={$type}"], ['class' => 'btn']);
?>
		<input type="submit" value="Update" />

		<?php 
ActiveForm::end();
?>
	</div>
</section>