public function actionIndex() { if (isset($_POST['CreatingForm'])) { $error = ''; $bodyMsg = array(); foreach ($_POST['CreatingForm'] as $id => $val) { $model = CreatingFormElements::model()->findByPk($id); //Проверяю, является ли поле обязательным и заполнено ли оно if ($model->feeld_require == 1 && empty($val)) { $error .= 'Поле `' . $model->name . '` обязательно для заполнения!' . "\n"; continue; } //Если поле E-mail - проверяю, что ввели email if ($model->feeld_type == 1) { preg_match('|([a-z0-9_\\.\\-]{1,20})@([a-z0-9\\.\\-]{1,20})\\.([a-z]{2,4})|is', $val, $match); if (empty($match)) { $error .= 'В поле `' . $model->name . '` указан неверный электронный адрес!' . "\n"; continue; } } //Пишем тело письма $bodyMsg[$model->name] = $val; } $answer = ''; if (!empty($error)) { //Есть ошибки - возвращаем их пользователю $answer = $error; } else { //Ошибок нет - отправляем письмо на почту $answer = empty($model->parent->complete_mess) ? 'Спасибо! Данные оправлены.' : $model->parent->complete_mess; $email = $model->parent->email_recipient; $title = $model->parent->subject_recipient; if (!empty($email) && !empty($title)) { preg_match('|([a-z0-9_\\.\\-]{1,20})@([a-z0-9\\.\\-]{1,20})\\.([a-z]{2,4})|is', $email, $match); if (!empty($match)) { $body = 'Сообщение с формы ' . $model->parent->name . ' сайта: ' . SITE_NAME_FULL . '<BR>'; $body .= ' <table border="1"> <thead> <th style="padding: 10px; background: #808080;">Поле</th> <th style="padding: 10px;">Ответ</th> </thead> <tbody> '; foreach ($bodyMsg as $name => $val) { $body .= ' <tr> <td style="padding: 10px; background: #808080;">' . $name . '</td> <td style="padding: 10px;" >' . $val . '</td> </tr>'; } $body .= '</tbody></table>'; $body .= '<BR>Дата заполнения отчета:' . date('d-m-Y H:i:s'); Yii::app()->mailer->send(array('email' => $email, 'subject' => $title, 'body' => $body)); } } } echo CJavaScript::jsonEncode($answer); } Yii::app()->end(); }
<legend><?php echo Yii::t("Bootstrap", "LIST.CreatingFormElements"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = CreatingFormElements::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'creating-form-elements-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["parent_id"], 'name' => "parent_id", 'value' => '$data->parent->name'), array('header' => $labels["feeld_type"], 'name' => "feeld_type", 'value' => 'CreatingFormRubrics::model()->getFeeldsTypes($data->feeld_type)'), array('header' => 'Порядок', 'name' => 'order_id', 'value' => function ($data) { return CHtml::textField('order_' . $data->id, $data->order_id, array("class" => "order", "data-id" => $data->id, "data-order" => $data->order_id)); }, 'type' => 'raw'), 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'))))); ?> <div class="buttons"> <a style="float:left;" href="/admin/<?php echo Yii::app()->controller->module->id; ?> /<?php echo Yii::app()->controller->id; ?> /create" class="btn">Создать поле формы</a> <a class="btn btn-success" style="float:left; margin-left:15px;" href="javascript: saveForm();">Сохранить изменения</a> </div>
<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;
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = CreatingFormElements::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionAjax() { if (isset($_POST)) { switch ((int) $_POST['type']) { case 1: //Смена статуса $model = $this->loadModel((int) $_POST['id']); $model->status = $model->status == 1 ? 0 : 1; $model->save(); //Меняем статус для полей в форме foreach (CreatingFormElements::model()->findAll('parent_id = ' . $model->id) as $data) { $data->status = $model->status; $data->save(); } break; } echo CJavaScript::jsonEncode('ok'); } Yii::app()->end(); }
/** * @param $id * Возвращает HTML код формы по id записи в tbl_creating_form_rubrics */ public function showForm($id) { $html = ''; if ($model = CreatingFormRubrics::model()->findByPk($id)) { //Форма $forms = '<form id="creating_form_' . $id . '" action="/apply_auto_form" method="POST">'; $forms .= !empty($model->form_template) ? $model->form_template : $this->def_form_template; $forms .= '</form>'; //Поля формы $feelds = ''; foreach (CreatingFormElements::model()->findAll('parent_id=' . $model->id . ' AND `status`=1 ORDER BY order_id ASC') as $data) { $feelds .= CreatingFormRubrics::model()->getFeeldHTML($data); } //Вешаем обработчик JS $forms .= ' <script> $("#creating_form_' . $id . '").submit(function() { $.ajax({ url: "/apply_auto_form", type: "POST", dataType: "json", data: $("#creating_form_' . $id . '").serialize(), success: function (response) { alert(response); }, }); return false; }); </script> '; $html = str_replace("%feelds_input%", $feelds, $forms); } return $html; }