public function addForm($body) { preg_match_all('/\\{myforms id=(\\d+)\\}/', $body, $matches); if (!empty($matches)) { $id = current($matches[1]); $body_feeld = CreatingFormRubrics::model()->showForm($id); $body = str_replace("{myforms id=" . $id . "}", $body_feeld, $body); } return $body; }
?> <!-- Fields with <span class="required">*</span> are required. --> <!--<p class="help-block"><?php echo Yii::t("Bootstrap", "PHRASE.FIELDS_REQUIRED"); ?> </p>--> <?php echo $form->errorSummary($model); ?> <?php echo $form->dropDownListRow($model, "parent_id", CHtml::listData(CreatingFormRubrics::model()->findAll(), "id", "name"), array('class' => 'span5')); echo $form->textFieldRow($model, 'name', array('class' => 'span5', 'maxlength' => 250)); echo $form->dropDownListRow($model, "feeld_type", CreatingFormRubrics::model()->getFeeldsTypes(), array('class' => 'span5')); echo $form->textFieldRow($model, 'feeld_value', array('class' => 'span5', 'maxlength' => 350)); echo $form->dropDownListRow($model, "feeld_require", array('Нет', 'Да'), array('class' => 'span5')); ?> <?php echo $form->textAreaRow($model, 'feeld_template', array('class' => 'span5', 'style' => 'min-height:200px;')); /* Yii::import('ext.imperavi-redactor-widget-master.ImperaviRedactorWidget'); echo $form->label($model,'feeld_template'); $this->widget('ImperaviRedactorWidget', array( 'model' => $model, 'attribute' => 'feeld_template', 'options' => array(
/** Для виджета в редакторе */ public function actionAjaxafrm() { if (isset($_POST)) { $result = ' <div id="formModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="formModalLabel" aria-hidden="true"> <div class="modal-header"> <a href="#" onclick="$(\'#formModal\').remove();" class="close">×</a> <h3 id="myModalLabel">Формы</h3> </div> <div class="modal-body"> '; $result .= '<table class="content_table hover_table" cellspacing="0">'; $result .= ' <thead> <tr> <th>Название</th><th>Действие</th> </tr> </thead> '; $result .= '<tbody>'; foreach (CreatingFormRubrics::model()->findAll('status=1') as $data) { $result .= '<tr>'; $result .= ' <td style="padding-left:20px; padding-right:20px;"> <b>' . $data->name . ':</b></br> '; $result .= ' </td> <td style="padding-left:20px; padding-right:20px;"> <a href="#" data-id="' . $data->id . '" data-class="' . $_POST['request'] . '" class="addMyForm">Вставить</a> </td> '; $result .= '</tr>'; } $result .= '</tbody>'; $result .= '</table>'; $result .= ' </div> </div> '; //Скрипт обработки нажатия 'Вставить' $result .= ' <script> $(document).on("click",".addMyForm",function(){ var html = "{myforms id="+$(this).data("id")+"}"; var className = $(this).data("class"); //Вставка фотогалереи $(".redactor-editor").redactor({ focus: true }); $("."+className).redactor("insert.html", html); $("#formModal").remove(); $(".redactor-editor").each(function(index, value){ $("#redactor-toolbar-"+(index+2)).remove(); }); return false; }); </script> '; echo $result; //echo CJavaScript::jsonEncode($result); } Yii::app()->end(); }
<legend><?php echo Yii::t("Bootstrap", "LIST.CreatingFormRubrics"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = CreatingFormRubrics::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'creating-form-rubrics-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $model->search(), 'filter' => null, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => $labels["name"], 'name' => "name"), array('header' => 'Полей', 'name' => "Полей", 'type' => 'raw', 'value' => function ($data) { $countFeels = CreatingFormElements::model()->count('parent_id=' . $data->id); return ' <a href="/admin/forms/creatingformelements?CreatingFormElements[parent_id]=' . $data->id . '"> <b>' . $countFeels . '</b> </a> '; }, 'filter' => ''), array('header' => 'Статус', 'name' => "status", 'type' => 'raw', 'value' => function ($data) { return ' <a href="#" class="on-off-product" data-id="' . $data->id . '" data-status="' . $data->status . '"> <div style="margin-left:20px; width: 13px; height: 13px; border-radius: 3px; background:' . ($data->status == 1 ? 'green' : 'red') . '"></div> </a> '; }, 'filter' => ''), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap'))))); ?> <a href="/admin/<?php echo Yii::app()->controller->module->id; ?> /<?php echo Yii::app()->controller->id;
/** * @param $model * Возращает HTML код поля */ public function getFeeldHTML($model) { $html = ''; //Если шаблон пустой - беру из дефолтного $model->feeld_template = !empty($model->feeld_template) ? $model->feeld_template : CreatingFormRubrics::model()->def_feeld_template; //Определяем, что за тип поля. По типу поля работаем со значением switch ($model->feeld_type) { case 1: //Поле ввода E-mail $model->feeld_template = str_replace("%feeld_name%", $model->name, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '<input type="text" name="CreatingForm[' . $model->id . ']" value="' . $model->feeld_value . '">', $model->feeld_template); $html = $model->feeld_template; break; case 2: //Короткое поле ввода (input) $model->feeld_template = str_replace("%feeld_name%", $model->name, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '<input type="text" name="CreatingForm[' . $model->id . ']" value="' . $model->feeld_value . '">', $model->feeld_template); $html = $model->feeld_template; break; case 3: //Большое поле ввода (textarea) $model->feeld_template = str_replace("%feeld_name%", $model->name, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '<textarea name="CreatingForm[' . $model->id . ']">' . $model->feeld_value . '</textarea>', $model->feeld_template); $html = $model->feeld_template; break; case 4: //Текст $model->feeld_template = str_replace("%feeld_name%", $model->feeld_value, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '', $model->feeld_template); $html = $model->feeld_template; break; case 5: //Дата - день, месяц и год $model->feeld_template = str_replace("%feeld_name%", $model->name, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '<input type="text" name="CreatingForm[' . $model->id . ']" value="' . $model->feeld_value . '">', $model->feeld_template); $html = $model->feeld_template; break; case 6: //Ссылка (в поле `Значение` укажите URL-адрес ссылки) $model->feeld_template = str_replace("%feeld_name%", '<a href="' . $model->feeld_value . '">' . $model->name . '</a>', $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '', $model->feeld_template); $html = $model->feeld_template; break; case 7: //Выпадающий список (варианты в выпадающем списке перечислите в поле `Значение` через символ ;) $model->feeld_value = $model->feeld_value . ';'; $selects = '<select name="CreatingForm[' . $model->id . ']">'; foreach (explode(";", $model->feeld_value) as $val) { if (empty($val)) { continue; } $selects .= '<option value="' . $val . '">' . $val . '</option>'; } $selects .= '</select>'; $model->feeld_template = str_replace("%feeld_name%", $model->name, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", $selects, $model->feeld_template); $html = $model->feeld_template; break; case 8: //Кнопка $model->feeld_template = str_replace("%feeld_name%", '', $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '<button value="' . $model->feeld_value . '" type="button" name="CreatingForm[' . $model->id . ']">' . $model->name . '</button>', $model->feeld_template); $html = $model->feeld_template; break; case 9: //Радио кнопка $model->feeld_value = $model->feeld_value . ';'; $radio = ''; foreach (explode(";", $model->feeld_value) as $val) { if (empty($val)) { continue; } $radio .= '<input type="radio" name="CreatingForm[' . $model->id . ']" value="' . $val . '">' . $val . '<Br>'; } $model->feeld_template = str_replace("%feeld_name%", $model->name, $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", $radio, $model->feeld_template); $html = $model->feeld_template; break; case 10: //Кнопка отправки формы $model->feeld_template = str_replace("%feeld_name%", '', $model->feeld_template); $model->feeld_template = str_replace("%feeld_val%", '<input type="submit" value="' . $model->name . '">', $model->feeld_template); $html = $model->feeld_template; break; } return $html; }