Message form tags

Description: Used to get the message form for background settings

How to use:{% guestbook 变量名称 %}Define variables as fields{% guestbook fields %}...{% endguestbook %}

The parameters supported by guestbook are

  • Site IDsiteId
    siteIdGenerally, there is no need to fill in it. If you use the background multi-site management to create multiple sites and want to call data from other sites, you can specify itsiteIdTo implement the data calling the specified site.

fields is an array object, so it needs to be usedforLoop to output

item is a variable in the for loop body. The available fields are:

  • Form nameName
  • Form variablesFieldName
  • Form TypeType
    There are 6 possible values ​​for form types: text typestext, number typenumber, multi-line text typetextarea, single-choice typeradio, Multiple Choice Typecheckbox, pull down to select typeselect.
  • Is it requiredRequired
    When the Required value is true, it means it is required. When the Required value is false, it means it can be ignored.
  • Form default valueContent
  • Default value for splitting into arraysItems
    When the form type is single-choice typeradio, Multiple Choice Typecheckbox, pull down to select typeselectWhen each of their selections forms an Items array that can be output via a for loop.

Submit message form

Submission of message form requires submission using form form, and the submission background reception address is:/guestbook.html, the fields that need to be submitted are

FieldsIs it requiredillustrate
user_nameyesUsername of the message
contactyesContact information, such as mobile phone, phone, WeChat, QQ, etc.
contentyesMessage content
Other custom fieldsDecide based on settingsAdd additional fields to form settings in the background, depending on whether the settings are required
ReturnnoAfter submission, specify the format returned by the backend, and the optional values ​​are:html,json, default to html

Code Example

Through the following code, you can loop out all set fields.

<form method="post" action="/guestbook.html">
{% guestbook fields %}
    {% for item in fields %}
    <div>
        <label>{{item.Name}}</label>
        <div>
            {% if item.Type == "text" || item.Type == "number" %}
            <input type="{{item.Type}}" name="{{item.FieldName}}" {% if item.Required %}required lay-verify="required"{% endif %} placeholder="{{item.Content}}" autocomplete="off">
            {% elif item.Type == "textarea" %}
            <textarea name="{{item.FieldName}}" {% if item.Required %}required lay-verify="required"{% endif %} placeholder="{{item.Content}}" rows="5"></textarea>
            {% elif item.Type == "radio" %}
            {%- for val in item.Items %}
            <input type="{{item.Type}}" name="{{item.FieldName}}" value="{{val}}" title="{{val}}">
            {%- endfor %}
            {% elif item.Type == "checkbox" %}
            {%- for val in item.Items %}
            <input type="{{item.Type}}" name="{{item.FieldName}}[]" value="{{val}}" title="{{val}}">
            {%- endfor %}
            {% elif item.Type == "select" %}
            <select name="{{item.FieldName}}">
                {%- for val in item.Items %}
                <option value="{{val}}">{{val}}</option>
                {%- endfor %}
            </select>
            {% endif %}
        </div>
    </div>
    {% endfor %}
    <div>
        <div>
            <button type="submit">提交留言</button>
            <button type="reset">重置</button>
        </div>
    </div>
{% endguestbook %}
</form>

If you want to customize the form display, you can also use regular input to organize the display, such as:

<form method="post" action="/guestbook.html">
  <input type="hidden" name="return" value="html">
  <div>
    <label>用户名</label>
    <div>
      <input type="text" name="user_name" required lay-verify="required" placeholder="请填写您的昵称" autocomplete="off">
    </div>
  </div>
  <div>
    <label>联系方式</label>
    <div>
      <input type="text" name="contact" required lay-verify="required" placeholder="请填写您的手机号或微信" autocomplete="off">
    </div>
  </div>
  <div>
    <label>留言内容内容</label>
    <div>
      <textarea name="content" placeholder="" id="comment-content-field" rows="5"></textarea>
    </div>
  </div>
    <div>
        <div>
            <button type="submit">提交留言</button>
            <button type="reset">重置</button>
        </div>
    </div>
</form>