How to quickly generate a customizable website guestbook form with the `guestbook` tag?

Calendar 👁️ 61

In website operation, interacting with visitors and collecting feedback is an important link to improve user experience and obtain valuable information. The message form is the core tool to achieve this goal. AnQiCMS (AnQiCMS) fully understands its importance and provides users withguestbookTag, allowing you to easily and flexibly build a powerful and highly customizable website message form.

UseguestbookLabel, you can not only quickly generate the basic message function, but also according to your business needs, add various custom fields to the form, so as to accurately collect the information you want, without touching the complex backend code.

Core feature: customizable field message form

The留言表单functionality of 安企CMS is powerful in its customizability.It allows you to define the fields required for the message form in the website backend management system, for example, in addition to the common name, contact information, and message content, you can also add various fields such as "Select service type", "reservation time", "upload file", and so on.These custom fields will directly affect the display form and the type of information collected by the front-end message form.

After you set these fields in the background, you just need to make a simple call in the front-end templateguestbookLabel, AnQi CMS will automatically generate the corresponding form elements according to your configuration.This greatly simplifies the development process, allowing content operators to easily handle the creation and management of forms.

Deep understandingguestbookTag

guestbookThe usage of tags is very intuitive: {% guestbook fields %}...{% endguestbook %}. Here,fieldsThis is an array object automatically generated by the Anqi CMS system based on the backend configuration. This array contains all the details of the fields you define for the comment form.

Let's take a look atfieldsEach element in the arrayitemWhich key attributes does each form field contain, they are the foundation for customization:

  • NameThis is the display name of the field, which is the label text that visitors see on the form, such as "Your Name", "Contact Email", etc.
  • FieldNameThis is the unique identifier used by the backend to recognize and store the field data, which is usually a string in English, such asuser_name/contact_email. This name will be sent as part of the data when the form is submitted.
  • TypeThis property is very critical, it determines the type of form element. Anqi CMS supports various types, including:
    • text(Single-line text input box)
    • number(Numeric input box)
    • textarea(Multi-line text area)
    • radio(Radio button group)
    • checkbox(Checkbox group)
    • select(Drop-down selection box)
  • RequiredA boolean value (trueorfalse),indicating whether the field is required. If it istrue,the front-end form will usually add corresponding validation rules.
  • ContentThis attribute is usually used as a placeholder for text input boxesplaceholder) or default value, providing visitors with a filling prompt.
  • ItemsWhen the field type isradio/checkboxorselectAt that time, this property will provide an array containing all the available option values.

Step by step build your message form.

Now, let's go through a real template code example to see how to useguestbooktags to quickly generate a customizable field comment form.

First, you need to make sure that you have already added custom fields, set their names, types, whether they are required, and options (if needed) in the 'Function Management' -> 'Website Message Management' section of the Anqin CMS backend.For example, you may have set "Name (text, required)", "Email (text, required)", "Service Type (select, options: Website Construction, SEO Optimization, Content Marketing)", "Message Content (textarea, required)".

Next, you can edit your message page template file (usuallyguestbook/index.htmlor your custom message page template) by writing the following code:

`twig

{# 用于系统识别提交来源和返回格式,如果需要json返回,可设置为json #}
<input type="hidden" name="return" value="html">

{% guestbook fields %}
    {% for item in fields %}
    <div class="form-group">
        <label for="{{ item.FieldName }}">{{ item.Name }}{% if item.Required %} *{% endif %}</label>
        <div>
            {% if item.Type == "text" or item.Type == "number" %}
            <input type="{{ item.Type }}"
                   id="{{ item.FieldName }}"
                   name="{{ item.FieldName }}"
                   {% if item.Required %}required{% endif %}
                   placeholder="{{ item.Content }}"
                   class="form-control">
            {% elif item.Type == "textarea" %}
            <textarea id="{{ item.FieldName }}"
                      name="{{ item.FieldName }}"
                      {% if item.Required %}required{% endif %}
                      placeholder="{{ item.Content }}"
                      rows="5"
                      class="form-control"></textarea>
            {% elif item.Type == "radio" %}
            <div class="form-check-group">
                {%- for val in item.Items %}
                <label class="form-check-label">
                    <input type="radio"
                           name="{{ item.FieldName }}"
                           value="{{ val }}"
                           {% if loop.first %}checked{% endif %} {# 默认选中第一个 #}
                           {% if item.Required %}required{% endif %}
                           class="form-check-input"> {{ val }}
                </label>
                {%- endfor %}
            </div>
            {% elif item.Type == "checkbox" %}
            <div class="form-check-group">
                {%- for val in item.Items %}
                <label class="form-check-label">
                    <input type="checkbox"
                           name="{{ item.FieldName }}[]" {# 多选框通常需要[]表示数组 #}
                           value="{{ val }}"
                           class="form-check-input"> {{ val }}
                </label>
                {%- endfor %}
            </div>
            {% elif item.Type == "select" %}
            <select id="{{ item.FieldName }}"
                    name="{{ item.FieldName }}"
                    {% if item.Required %}required{% endif %}
                    class="form-control">
                {%- for val in item.Items %}
                <option value="{{ val }}">{{ val }}</option>
                {%- endfor %}
            </select>
            {% endif %}
        </div>
    </div>
    {% endfor %}

    {# 留言验证码,如果后台开启,需集成 #}
    {# 详情请参考 tag-/anqiapi-other/167.html 文档 #}
    {#
    <div class="form-group captcha-group">
        <label for="captcha">验证码 {% if system.guestbook_captcha_open %}*{% endif %}</label>
        <div style="display: flex; align-items: center;">
            <input type="hidden" name="captcha_id" id="captcha_

Related articles

How to display the comment list and pagination on the article detail page with the `commentList` tag?

In AnQi CMS, the comment list on the article detail page is an important component for enhancing user interaction and content vitality.To naturally and smoothly display these comments and achieve a friendly pagination experience, we need to cleverly use the `commentList` and `pagination` template tags.Next, let's take a look at how to implement the display and pagination of comments on the article detail page.

2025-11-08

How does the `tagDataList` tag display all document lists under a specific tag?

In Anqi CMS, managing and displaying content, the tag (Tag) is undoubtedly a very practical tool.It can help us organize documents more flexibly, realize multi-dimensional content aggregation, and greatly benefit the improvement of the website's SEO performance and user experience.When we need to display a list of all documents under a specific tag page, or at any location on the website, the `tagDataList` tag is an indispensable tool.###

2025-11-08

How to retrieve and display the details of a specific `tagDetail` tag?

AnQiCMS (AnQiCMS) provides a series of powerful template tags to help website operators efficiently display content.Among them, the `tagDetail` tag is a key tool for obtaining and displaying specific tag details.Whether it is to build a beautiful tag detail page or to refer to related data of tags on other pages, `tagDetail` can provide a flexible and intuitive solution.

2025-11-08

How to display the associated tags of the `tagList` and implement a tag cloud effect?

## Utilizing AnQiCMS's `tagList` tag, easily implement document association and tag cloud display Tags play a crucial role in website content operations.They can not only help users quickly find the content they are interested in, improve the convenience of site navigation, but also optimize the search engine's understanding of the website's content through keyword aggregation, thereby bringing better SEO performance.AnQiCMS fully considered this requirement, built-in powerful tag features, and provided flexible template tags `tagList`

2025-11-08

How to use the `linkList` tag to display the list of friends' links on the website?

During the operation of our website, friendship links not only help to increase the amount of traffic, but are also an indispensable part of SEO optimization.A healthy link ecosystem that can effectively pass on weight and enhance the authority of the website.In AnqiCMS, managing and displaying friend links is very convenient, mainly due to its built-in `linkList` tag.This article will introduce in detail how to use the `linkList` tag to display the friend link list on your AnqiCMS website.

2025-11-08

How to use the `pagination` tag to generate a beautiful pagination navigation for articles or product lists?

In website operation, as the content volume continues to grow, whether it is articles, products, or other lists, how to efficiently organize and display these contents while ensuring a smooth user browsing experience and a friendly search engine is a problem that needs to be carefully considered.Page navigation is the key tool to solve this problem.AnQiCMS provides a powerful and flexible `pagination` tag that allows you to easily create beautiful and functional pagination navigation for various lists.

2025-11-08

How to flexibly control the conditional display and loop iteration of logic tags such as `if` and `for` in the template?

In the world of AnQi CMS templates, we often need to display content based on different conditions or repeat a series of data, at this point, the `if` and `for` logical tags become particularly important.They are the foundation for building dynamic content and implementing flexible layouts in templates, allowing us to precisely control the presentation of every piece of information on the web page.

2025-11-08

How to use the `stampToDate` tag to format a database timestamp into a readable date?

In website operation, we often encounter such situations: the time information stored in the database, such as the publication time of articles, the creation time of goods, etc., is often in the form of a series of numbers (timestamps).This string of numbers is clear to machines, but it has poor readability for us users.Imagine, if next to an article it displays '1678886400' instead of '2023/03/15', wouldn't that be a big discount in experience?AnQi CMS knows this and has provided a very practical template tag——`stampToDate`

2025-11-08