How to build and display an online comment form and its custom fields in Anqi CMS?

Calendar 👁️ 63

A strong and flexible online message function is provided by AnQi CMS, which not only allows you to build a basic contact form, but also can customize various fields according to business needs, thereby collecting more accurate user feedback.Below, we will explore how to easily build and display these comment forms in Anqi CMS.

One, configure the message form and custom fields in the Anqi CMS background

To start building your online message form, you first need to log in to the Anqi CMS backend management interface.

  1. Access the message management module:After logging in to the backend, please navigate to the "Function Management" area in the left menu, then click "Website Messages". This is the central location for all message-related settings.
  2. The default field and custom field:Anqi CMS will provide some core fields for the comment form, such as user name(user_name)、Contact Information(contact) and message content (content)。Except for this basic information, you can add an unlimited number of custom fields according to your actual business needs.
    • Add custom field:On the "Website Feedback" page, you will find the option to add a new field. Click to enter and configure the following key information:
      • Field Name:This is the field label displayed to the user on the front-end interface, for example, 'Your industry', 'Select service type', etc. Please ensure it is clear and understandable.
      • Field Name (FieldName):This is the unique identifier for the field referenced in the template code. It is recommended to use a combination of lowercase letters and underscores, such asyour_industry. Once set, it is not recommended to change it arbitrarily, as it will affect the calling of the front-end template.
      • Field type:AnQi CMS provides various field types to meet the collection needs of different data, including:
        • Single-line text (text):Suitable for short text input, such as names, company names.
        • Number (number):Only numeric input is allowed, such as age, budget amount.
        • Multi-line text (textarea):Suitable for long text input, such as detailed descriptions, suggestions.
        • Single choice (radio):Users can only select one from the preset options.
        • Multiple selection (checkbox):Users can select multiple preset options.
        • Dropdown selection (select):Users can select an option from a dropdown menu.
      • Mandatory?:Check this box, then this field must be filled in when submitted on the front end.
      • Default/Option Value:For text, number, and multiline text types, you can set a default prompt value here.For radio, checkbox, and dropdown selection types, here you need to enter all the available options, each on a new line.

In this way, you can build a highly customized feedback form, whether it is to collect the industry of the user, specific needs, or preferred contact time, it can be easily realized.

Second, display the message form in the front-end template

After the background configuration is complete, the next step is to display the carefully designed feedback form on the front end of your website.Anqi CMS adopts a flexible template tag system, making this process simple.

  1. Select an appropriate template file:Your online feedback form is usually placed on a dedicated page. According to Anqi CMS template conventions, the default online feedback page file isguestbook/index.htmlYou can also choose to embed it into other single-page applications (such as "Contact Us") or any page that requires a form.

  2. UseguestbookLabel field acquisition:In the selected template file, you can use the security CMS providedguestbookThe tag to get all the background configuration fields of comments. This tag will pass all the fields as an array object to you.

    <form method="post" action="/guestbook.html" id="guestbookForm">
        {% guestbook fields %}
            {# 在这里循环输出每个字段 #}
        {% endguestbook %}
    
        {# 留言提交按钮 #}
        <div>
            <button type="submit">提交留言</button>
            <button type="reset">重置</button>
        </div>
    </form>
    

    action="/guestbook.html"Indicates the backend processing address for form submission.

  3. Loop rendering form fields: fieldsThe variable is an array that contains information about each field you configure in the background. You can useforLoop through this array and dynamically generate the corresponding HTML form elements based on the type of each field.

    `twig

    {% guestbook fields %}
        {% for item in fields %}
        <div class="form-group">
            <label for="{{ item.FieldName }}">{{ item.Name }} {% if item.Required %}<span class="text-danger">*</span>{% 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" %}
                    {% for val in item.Items %}
                    <input type="radio" id="{{ item.FieldName }}_{{ forloop.Counter }}" name="{{ item.FieldName }}" value="{{ val }}" {% if item.Required and forloop.Counter == 1 %}required{% endif %}>
                    <label for="{{ item.FieldName }}_{{ forloop.Counter }}">{{ val }}</label>
                    {% endfor %}
                {% elif item.Type == "checkbox" %}
                    {% for val in item.Items %}
                    <input type="checkbox" id="{{ item.FieldName }}_{{ forloop.Counter }}" name="{{ item.FieldName }}[]" value="{{ val }}" {% if item.Required and forloop.Counter == 1 %}required{% endif %}>
                    <label for="{{ item.FieldName }}_{{ forloop.Counter }}">{{ val }}</label>
                    {% endfor %}
                {% 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 %}
    
        {# 集成验证码,增强安全性 #}
        <div class="form-group captcha-group">
            <label for="captcha">验证码 <span class="text-danger">*</span></label>
            <div class="d-flex">
                <input type="hidden" name="captcha_id" id="captcha_id">
                <input type="text" name="captcha" required placeholder="请填写验证码" class="form-control captcha-input">
                <img src="" id="get-captcha" class="captcha-img" alt="验证码">
            </div>
            <script>
                document.getElementById('get-captcha').addEventListener("click", function () {
                  fetch('/api/captcha')
                          .then(response => response.json())
                          .then(res => {
                            document.getElementById('captcha_id').value = res.data.captcha_id
    

Related articles

How does Anqi CMS display the website visitor's comment list and its reply relationship?

When building and maintaining an active website, visitor interaction is a crucial aspect.The comment system not only enhances the discussion热度 of the website content, strengthens user stickiness, but also brings new content to the website and has a positive impact on search engine optimization (SEO).AnQiCMS (AnQiCMS) fully understands this, and therefore its built-in comment feature provides strong and flexible support for displaying comment lists, handling reply relationships, and managing comments.

2025-11-08

How to implement the hierarchical display of custom navigation menus in Anqi CMS templates?

To implement hierarchical display of custom navigation menus in AnQi CMS is an important link to improve the user experience and content organization of the website.AnQiCMS provides flexible backend configuration and powerful template tags, allowing users to easily build clear and easy-to-navigate multi-level navigation menus. ### Customize Navigation Menu in Backend To achieve hierarchical display of the navigation menu, you first need to make the corresponding configuration in the AnQiCMS backend.In the background management interface, find the "Background Settings" menu under the "Navigation Settings" option

2025-11-08

Does AnQi CMS support rendering Markdown formatted text in the content as HTML?

Anqi CMS is an efficient and customizable content management system that has always been committed to providing modern and convenient solutions in content creation and presentation.For many content creators, Markdown, with its concise and efficient features, has become an indispensable tool for daily writing.Then, does AnQi CMS support Markdown formatted text and render it as HTML to display normally on the front-end page?The answer is affirmative, Anqi CMS provides comprehensive support for Markdown, with high integration and smooth operation. Firstly

2025-11-08

How to set the SEO title, keywords, and description (TDK) of a website to display in search results in Anqi CMS?

## Optimize Search Visibility: Detailed Guide to Fine-tuning Website SEO Title, Keywords, and Description (TDK) in AnQi CMS In the digital world, the visibility of a website is the key to its success.When a user searches for information through a search engine, the way your website is displayed in the search results directly affects whether they will click to enter.This, the website's SEO title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, play a crucial role

2025-11-08

How does Anqi CMS handle and display remote images, is it downloaded locally or directly referenced?

In website content management, effective image processing is crucial for improving page loading speed, user experience, and even SEO performance.AnQiCMS (AnQiCMS) provides flexible and practical strategies for handling remote images referenced in content, mainly manifested in two ways: downloading them to the local server for management or directly referencing the original link of the remote image.Both of these methods have their own focus, meeting the needs of different operation scenarios.**The core processing mechanism of AnQi CMS for remote images** AnQi CMS encounters remote image links in the content editor

2025-11-08

How to display the single page content of a specified ID in Anqi CMS, such as 'About Us'?

In AnQi CMS, whether it is to display a corporate profile like "About Us" or static content such as "Contact Information", "Terms of Service", the single-page feature is very practical.It allows you to create independent pages that do not belong to any category and provides a flexible way to control the display of these pages. To make the Anqie CMS display the single page content of a specified ID, you will mainly use the built-in template tags and the page management function of the back-end.This makes it very convenient to customize exclusive layouts at any location on the website or for specific single-page websites.

2025-11-08

Does AnQi CMS support the display of mathematical formulas and flowcharts in article content?

In content creation, especially in technical articles, academic papers, or project documents, we often need to present complex mathematical formulas and clear flowcharts to enhance the professionalism and readability of the content.For users of AnQiCMS, this is indeed a very practical need.Then, does Anqi CMS support displaying mathematical formulas and flowcharts in article content?The answer is affirmative, and it is not complex to implement. AnQi CMS provides flexible and diverse content management methods for content creators, one of which is the built-in Markdown editor.

2025-11-08

How to get and display the list of friend links in Anqi CMS?

In website operation, friendship links (also known as friend links) are an important component for improving website authority, increasing external traffic, and promoting interaction between websites.A well-maintained list of friendship links, which can not only increase the external links of the website and have a positive effect on SEO, but also provide users with more relevant information and improve the user experience.AnQi CMS knows its importance and provides an intuitive and user-friendly backend management interface and convenient template calling method, allowing you to easily obtain and display the list of friend links. We will introduce in detail how to implement this feature in Anqi CMS.--- ##

2025-11-08