dmstr / yii2-contact-module

Yii 2.0 框架的联系方式表单管理器

安装次数: 41,375

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 6

分支: 1

公开问题: 1

类型:yii2-extension


README

导航到 /contact/crud/contact-template 以创建新的表单模板。

升级提示

  • 如果表单是用版本 <= 1.0.0 构建的,则存在这样的约定,即您模式中的属性 reply_to 用作消息中的 'Reply-To:' 报头。
  • 这种“魔法”已被移除!您现在必须将 'Reply to Schema Property' 设置为 'reply_to' 以获得相同的行为!

Twig 模板(视图)

每个表单需要 2 个 Twig 模板。导航到 /prototype/twig/index 以创建它们

  • contact:FORM_NAME:将渲染表单的模板
  • contact:FORM_NAME:send:将在消息发送后渲染为“感谢页面”

其中 FORM_NAME 必须替换为您的模板名称

  • 表单可以在 /contact/default/?schema=FORM_NAME 中查看
  • “感谢页面”可以在 /contact/default/done?schema=FORM_NAME 中查看

表单 Twig 布局

{{ use('dmstr/jsoneditor/JsonEditorWidget') }}
{{ use('yii/widgets/ActiveForm') }}

<div class="container">
    <div class="row">
        <div class="col-md-12">
            {% set form = active_form_begin({
                'id': 'contact-form',
                'action' : '',
                'options': {
                }
            }) %}
    
            {{ form.errorSummary(model) | raw }}
    
            {{ json_editor_widget_widget({
                'model': model,
                'attribute': 'json',
                'options': {
                    'id': 'contact-json'
                },
                'clientOptions': {
                    'theme': 'bootstrap3',
                    'disable_collapse': true,
                    'disable_edit_json': true,
                    'disable_properties': true,
                    'no_additional_properties': true,
                    'show_errors': 'interaction'
                },
                'schema': schema,
            }) }}

            <button type="submit" class="btn btn-primary">{{ t('twig-widget', 'Send') }}</button>
            
            {{ active_form_end() }}
        </div>
    </div>
</div>

带有 captcha 的表单 Twig 布局(需要在 contact-template 中激活 captcha)

{{ use('dmstr/jsoneditor/JsonEditorWidget') }}
{{ use('yii/widgets/ActiveForm') }}
{{ use('yii/captcha/Captcha') }}

<div class="container">
    <div class="row">
        <div class="col-md-12">
            {% set form = active_form_begin({
                'id': 'contact-form',
                'action' : '',
                'options': {
                }
            }) %}
    
            {{ form.errorSummary(model) | raw }}
    
            {{ json_editor_widget_widget({
                'model': model,
                'attribute': 'json',
                'options': {
                    'id': 'contact-json'
                },
                'clientOptions': {
                    'theme': 'bootstrap3',
                    'disable_collapse': true,
                    'disable_edit_json': true,
                    'disable_properties': true,
                    'no_additional_properties': true,
                    'show_errors': 'interaction'
                },
                'schema': schema,
            }) }}

            {{ Captcha_widget({
                model: model,
                attribute: 'captcha',
                captchaAction: '/contact/default/captcha'
            }) }}

            <button type="submit" class="btn btn-primary">{{ t('twig-widget', 'Send') }}</button>
            
            {{ active_form_end() }}
        </div>
    </div>
</div>
  • captcha 的背景和前景颜色可以在设置模块的 captcha 部分下定义。它使用特定的颜色格式,但最后 6 个字符遵循 css 十六进制颜色代码(例如 0xff0000 是红色,0x00ff00 是绿色)

“感谢页面” Twig 布局

<div class="alert alert-success">{{ t('twig-widget', 'Thank you for your message') }}</div>

联系方式表单 widgets twig 示例

{{ use('dmstr/modules/contact/widgets/ContactForm') }}

{{ contact_form_widget({schemaName: schemaName}) }}

设置模式

{
  "title": " ",
  "type": "object",
  "format": "grid",
  "properties": {
    "Company": {
      "type": "string",
      "minLength": 3,
      "title": "Firma",
      "propertyOrder": 5,
      "options": {
        "grid_columns": 12
      }
    },
    "Title": {
      "type": "string",
      "title": "Anrede",
      "minLength": 1,
      "propertyOrder": 10,
      "enum": [
        "Herr",
        "Frau"
      ],
      "options": {
        "enum_titles": [
          "Herr",
          "Frau"
        ],
        "grid_columns": 2
      }
    },
    "LastName": {
      "type": "string",
      "minLength": 3,
      "title": "Name",
      "propertyOrder": 20,
      "options": {
        "grid_columns": 5
      }
    },
    "SurName": {
      "type": "string",
      "minLength": 3,
      "title": "Vorname",
      "propertyOrder": 30,
      "options": {
        "grid_columns": 5
      }
    },
    "Zip": {
      "type": "string",
      "minLength": 5,
      "title": "PLZ",
      "propertyOrder": 40,
      "options": {
        "grid_columns": 2
      }
    },
    "Location": {
      "type": "string",
      "minLength": 3,
      "title": "Ort",
      "propertyOrder": 50,
      "options": {
        "grid_columns": 5
      }
    },
    "Street": {
      "type": "string",
      "title": "Straße/Hausnr.",
      "minLength": 5,
      "propertyOrder": 60,
      "options": {
        "grid_columns": 5
      }
    },
    "Phone": {
      "type": "string",
      "title": "Telefon",
      "minLength": 6,
      "propertyOrder": 60,
      "options": {
        "grid_columns": 5
      }
    },
    "Fax": {
      "type": "string",
      "title": "Fax",
      "propertyOrder": 60,
      "options": {
        "grid_columns": 5
      }
    },
    "Email": {
      "type": "string",
      "format": "email",
      "minLength": 1,
      "title": "E-Mail Adresse",
      "propertyOrder": 70,
      "options": {
        "grid_columns": 6
      }
    },
    "Internet": {
      "type": "string",
      "title": "Internet",
      "propertyOrder": 70,
      "options": {
        "grid_columns": 6
      }
    },
    "Message": {
      "type": "string",
      "format": "textarea",
      "title": "Nachricht (stichwortartig)",
      "propertyOrder": 90,
      "options": {
        "grid_columns": 12
      }
    }
  }
}

导出

要启用导出功能,请将 kartik\grid\Module 添加到您的项目模块中