FormWidget

A simple example

\skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget::widget([
    'namespace' => 'FormWidget-contacts',
    'form_code' => 'feedback' //The code forms collected through the administrative part
]);

Basic template messages sending

\skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget::widget([
    'namespace' => 'FormWidget-contacts',
    'form_code' => 'feedback'              //The code forms collected through the administrative part
    'viewFile' => 'whith-messages',        //The default form comes with a widget
]);

Available basic templates https://github.com/skeeks-cms/cms-module-form2/tree/master/cmsWidgets/form2/views


How to use your own template

\skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget::widget([
    'namespace' => 'FormWidget-contacts',
    'form_code' => 'feedback'              //The code forms collected through the administrative part
    'viewFile' => '@app/view/my-form-template',
]);

Content template

<?php
/**
 * @author Semenov Alexander <semenov@skeeks.com>
 * @link http://skeeks.com/
 * @copyright 2010 SkeekS (СкикС)
 * @date 17.03.2015
 *
 * @var $widget \skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget
 */
$modelHasRelatedProperties = $widget->modelForm->createModelFormSend();
?>
    <?php $form = skeeks\modules\cms\form2\widgets\ActiveFormConstructForm::begin([
        'id'                                        => $widget->id . "-active-form",
        'modelForm'                                 => $widget->modelForm,
        'afterValidateCallback'                     => new \yii\web\JsExpression(<<<JS
            function(jForm, ajax)
            {
                var handler = new sx.classes.AjaxHandlerStandartRespose(ajax, {
                    'blockerSelector' : '#' + jForm.attr('id'),
                    'enableBlocker' : true,
                });
                handler.bind('error', function(e, data)
                {
                    $('.sx-success-message', jForm).hide();
                    $('.sx-error-message', jForm).show();
                    $('.sx-error-message .sx-body', jForm).empty().append(data.message);
                });
                handler.bind('success', function(e, data)
                {
                    $('.sx-error-message', jForm).hide();
                    $('.sx-success-message', jForm).show();
                    $('.sx-success-message .sx-body', jForm).empty().append(data.message);
                    $('input, textarea', jForm).each(function(value, key)
                    {
                        var name = $(this).attr('name');
                        if (name != '_csrf' && name != 'sx-model-value' && name != 'sx-model')
                        {
                            $(this).val('');
                        }
                    });
                });
            }
JS
),
    ]);
?>

<?= \yii\bootstrap\Alert::widget([
    'options' => [
        'class' => 'alert-success sx-success-message',
        'style' => 'display: none;',
    ],
    'closeButton' => false,
    'body' => '<div class="sx-body">Ok</div>',
])?>

<?= \yii\bootstrap\Alert::widget([
    'options' => [
        'class' => 'alert-danger sx-error-message',
        'style' => 'display: none;',
    ],
    'closeButton' => false,
    'body' => '<div class="sx-body">Ok</div>',
])?>

<? if ($properties = $modelHasRelatedProperties->relatedProperties) : ?>
    <? foreach ($properties as $property) : ?>
        <?= $property->renderActiveForm($form, $modelHasRelatedProperties); ?>
    <? endforeach; ?>
<? endif; ?>

<?= \yii\helpers\Html::submitButton("" . \Yii::t('app', $widget->btnSubmit), [
    'class' => $widget->btnSubmitClass,
]); ?>

<?php skeeks\modules\cms\form2\widgets\ActiveFormConstructForm::end(); ?>

Пример использования с модальными окнами

<? $modal = \yii\bootstrap\Modal::begin([
    'header' => 'Заказать звонок',
    'toggleButton' => [
        'label' => '<i class="fa fa-phone"></i> Заказать звонок',
        'class' => 'call-me btn btn-lg btn-blue hidden-xs',
    ],
]); ?>
    <? \skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget::beginWidget('phone', [
        'form_code' => 'callback',
        'viewFile' => 'with-messages',
        'successJs' => <<<JS
function(jForm, data)
{
_.delay(function()
{
$("#{$modal->id}").modal('hide');
}, 1500);

}
JS
,


    ]); ?>
    <? \skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget::end(); ?>
<? \yii\bootstrap\Modal::end(); ?>

 


Все комментарии (0)
Нет комментариев