robuust/craft-laposta

Laposta forms for Craft 4

安装: 798

依赖项: 0

建议者: 0

安全: 0

星级: 1

关注者: 2

分支: 2

开放问题: 0

类型:craft-plugin

3.0.1 2024-08-29 12:42 UTC

This package is auto-updated.

Last update: 2024-08-29 12:42:41 UTC


README

一个允许你显示 Laposta 表单的插件

要求

此插件需要 Craft CMS 4.0.0 或更高版本。

安装

要安装此插件,请按照以下说明操作。

  1. 打开您的终端并转到您的 Craft 项目目录

     cd /path/to/project
    
  2. 然后告诉 Composer 加载插件

     composer require robuust/craft-laposta
    
  3. 在控制面板中,转到设置 → 插件,并为 Laposta 点击“安装”按钮。

配置

在您的 Craft 配置文件夹中创建一个名为 laposta.php 的文件,并包含以下内容

<?php

return [
    // General
    'apiKey' => 'YOUR_API_KEY',
];

使用方法

创建一个新的“Laposta”字段并将其添加到所需元素的字段布局中。现在,在编辑此类元素时,您可以选择要使用的 Laposta 列表。

在您的前端模板中,您可以渲染此 Laposta 列表为表单。

示例

以下是一个渲染 Laposta 表单的示例。您可以根据需要更改和样式化此示例。

  {% if errors is defined %}
    <p>{{ errors.message|t }}</p>
  {% endif %}
  <form method="post">
    {{ csrfInput() }}
    {{ actionInput('laposta/submit') }}
    {{ redirectInput('url_to_redirect_to') }}
    {% for field in entry.form|filter(field => field.inform == "true") %}
      {% switch field.type %}
        {% case 'radio' or 'checkbox' %}
          {% for option in field.options %}
            <input id="{{ field.id }}-{{ loop.index }}" name="{{ field.name }}{% if field.type == 'checkbox' %}[]{% endif %}" type="{{ field.type }}" {% if field.required %} required{% endif %} value="{{ option }}" /> <label for="{{ field.id }}-{{ loop.index }}">{{ option }}</label>
          {% endfor %}
        {% default %}
          <input id="{{ field.id }}" name="{{ field.name }}" type="{{ field.type }}" placeholder="{{ field.label }}"{% if field.required %} required{% endif %} value="{{ field.value }}" />
      {% endswitch %}
      <br />
    {% endfor %}
    <input type="submit" />
  </form>