Message form tags

Description: Used to get the message form for background settings

How to use:{% guestbook 变量名称 %}If the variable is defined 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 the variable within the for loop, and the available fields are:

  • Form nameName
  • Form variablesFieldName
  • Form TypeTypeThere are 6 possible values for the form type: text typetext, number typenumber, multi-line text typetextarea, single-choice typeradio, Multiple Choice Typecheckbox, pull down to select typeselect.
  • Is it requiredRequiredWhen 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 arraysItemsWhen 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

Fields Is it required illustrate
user_name yes Username of the message
contact yes Contact information, such as mobile phone, telephone, WeChat, QQ, etc.
content yes Message content
Other custom fields Decide based on settings Add additional fields to form settings in the background, depending on whether the settings are required
Return no After 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 the conventional 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>