Message Form Label

Description: Used to obtain the backend settings for the leave form

Usage:{% guestbook 变量名称 %}If the variable is defined as fields{% guestbook fields %}...{% endguestbook %}

The guestbook supports the following parameters

  • Site IDsiteId siteIdGenerally, it is not necessary to fill in, if you use the multi-site management on the backend to create multiple sites and want to call data from other sites, you can specifysiteIdTo call the data of the specified site.

fields is an array object, therefore it needs to be usedforloop to output

item is the variable within the for loop, available fields include:

  • Form nameName
  • Form variableFieldName
  • Form typeTypeThere are 6 possible values for form type: text typetextNumber TypenumberMulti-line Text TypetextareaSingle Choice TyperadioMultiple Choice TypecheckboxDropdown Choice Typeselect.
  • Mandatory?RequiredRequired The value is true when it indicates that it is required, and the value is false when it indicates that it is not required.
  • Form default valueContent
  • The default value to split into an arrayItemsWhen the form type is Single choice typeradioMultiple Choice TypecheckboxDropdown Choice TypeselectWhen, each of their options constitutes an Items array, which can be output through a for loop.

Submit message form

The message form needs to be submitted using a form, the submission backend receiving address is:/guestbook.htmlThe fields that need to be submitted are:

field Mandatory? Description
user_name Is The username of the message poster
contact Is Contact information, such as mobile phone, landline, WeChat, QQ, etc.
content Is Message content
Other custom field Decided according to the settings Fields set for additional form field settings on the backend, whether they are required or not according to the settings
return No After submission, specify the format returned by the backend, the optional values are:html/jsonDefault is html

Code example

You can loop through all the fields set below with the following code.

<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, like:

<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>