How to synchronize the newly added custom message field in the AnQiCMS backend to the frontend message form?

Calendar 👁️ 59

Certainly, as an experienced website operation expert, I am very willing to give you a detailed explanation of how to seamlessly synchronize the custom message field in AnQiCMS with the front-end message form.AnQi CMS, with its flexible and efficient design concept, indeed provides many considerate features in content management, and the customized message field is one of the highlights, which can help us collect user feedback information more accurately.


AnQi CMS: Allow custom message fields to seamlessly integrate into the front-end form and achieve seamless interaction!

In daily website operations, we often need to collect specific information from users in addition to their names, contact information, and message content.It may be the industry type of the user, the products they are interested in, or even the time period they want to revisit.AnQi CMS understands the importance of this personalized need, therefore it has built a powerful custom message field feature, allowing you to flexibly configure it in the background and naturally present it in the front-end form.

How does the newly added custom message field in the background 'magically' synchronize with our website's message form and interact with users?This is actually a process with clever design and clear logic.

Step 1: Create your custom message field in the background.

First, everything starts at the AnQiCMS backend management interface. You will find that underfunction managementthere is awebsite messageoption. Click on it and you can findCustom message fieldSetting entry.

Here, you can add various types of fields according to business needs.For example, if you want to understand the industry of the user, you can create a field called "Industry Type"; if you want to provide several preset options for users to choose from, such as "Product Consultation", "Technical Support", "Business Negotiation", then single-choice or multiple-choice fields come into play.The Anqi CMS supports a variety of field types including single-line text, numbers, multi-line text, single selection, multiple selection, and drop-down selection, etc., and can almost meet all common form requirements.

There are two key points to pay special attention to when creating:

  • Parameter name (Name)This is the field name you see in the background, used for management and identification.
  • Field call (FieldName)This is the real 'behind-the-scenes hero', the unique identifier stored in the database and called in the front-end template. Make sure it is named according to standards and easy to understand, as it will be the corresponding input box in the front-end form.nameProperty value.

Set the field name, call the field, choose the appropriate field type, define the default value or options (if needed), and then check whether it is required according to the actual situation.After saving, this information about custom fields is silently stored inside AnQiCMS.

Step two: The 'Magician' in the front-end template——“guestbookTag

Next, we need to make these backend-configured field information appear on the front page.This is where our front-end template file comes in.guestbook/index.htmlthe file.

In this template file, Anqi CMS provides a very core and convenient tag——“{% guestbook fields %}. It is like a magician, able to encapsulate all the field information you configure in the background, into a collection namedfields, and pass it to the frontend template.

You need to use this tag in your form structure to retrieve field data.fieldsVariables essentially are an array (Slice) that contains all custom field information, with each array element representing a custom field you have created in the background.

Step 3: Dynamically render custom fields, build a form

Get itfieldsAfter this data set, the next step is to traverse it through a loop to dynamically generate front-end form elements. The Anqi CMS template engine (based on the Iris framework in Go language, supporting Django template syntax) provides powerfulforLoop and conditional judgment functions make this process extremely flexible.

Generally, we would use a{% for item in fields %}to loop throughfieldsarray. Inside the loop, eachitemRepresents a custom field, it will contain the fieldName(Display name),FieldName(Field name),Type(Field type),Required(Is required) as wellContent(Default value or placeholder) andItems(Option list, for single-choice, multiple-choice, dropdown selection).

By judgmentitem.TypeThe value, we can generate different types of HTML form elements:

<form method="post" action="/guestbook.html">
    <!-- 基础字段,例如用户名、联系方式、留言内容,如果后台有对应设置,也可在此循环中生成 -->
    <div>
        <label for="user_name">您的姓名</label>
        <input type="text" id="user_name" name="user_name" required placeholder="请填写您的姓名">
    </div>
    <div>
        <label for="contact">联系方式</label>
        <input type="text" id="contact" name="contact" required placeholder="手机/邮箱/微信/QQ">
    </div>

    <!-- 动态生成的自定义字段区域 -->
    {% guestbook fields %}
        {% for item in fields %}
            <div>
                <label for="{{ item.FieldName }}">{{ item.Name }}</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 }}" autocomplete="off">
                    {% elif item.Type == "textarea" %}
                        <textarea id="{{ item.FieldName }}" name="{{ item.FieldName }}" {% if item.Required %}required{% endif %} placeholder="{{ item.Content }}" rows="5"></textarea>
                    {% elif item.Type == "radio" %}
                        {%- for val in item.Items %}
                            <label><input type="radio" name="{{ item.FieldName }}" value="{{ val }}" {% if item.Required %}required{% endif %}> {{ val }}</label>
                        {%- endfor %}
                    {% elif item.Type == "checkbox" %}
                        {%- for val in item.Items %}
                            <label><input type="checkbox" name="{{ item.FieldName }}[]" value="{{ val }}"> {{ val }}</label>
                        {%- endfor %}
                    {% elif item.Type == "select" %}
                        <select id="{{ item.FieldName }}" name="{{ item.FieldName }}" {% if item.Required %}required{% endif %}>
                            {%- for val in item.Items %}
                                <option value="{{ val }}">{{ val }}</option>
                            {%- endfor %}
                        </select>
                    {% endif %}
                </div>
            </div>
        {% endfor %}
    {% endguestbook %}

    <!-- 验证码(如果启用) -->
    {% include "partial/captcha_guestbook.html" if_exists %} {# 假设验证码是一个单独引入的片段 #}

    <div>
        <button type="submit">提交留言</button>
        <button type="reset">重置</button>
    </div>
</form>

The key point is:

  • name="{{ item.FieldName }}"This is the core to synchronize front-end and back-end. The properties of front-end form elements must match thenameattributes set by the back-end.Calling field (FieldName)Absolutely consistent, so that the background can correctly identify and receive the value of this field.
  • id="{{ item.FieldName }}": Although it is not mandatory, but to set a uniqueidContributes to front-end JS operations and improves accessibility.
  • {% if item.Required %}required{% endif %}: Automatically adds the required HTML5 attributes based on backend settings.
  • For multiple choice items(checkbox),namethe attribute needs to be added[]For examplename="{{ item.FieldName }}[]"So that the backend can receive an array of values.

Through such a dynamic rendering mechanism, regardless of how many custom message fields you add, modify, or delete in the background, the front-end form will automatically update accordingly, without the need to manually modify the front-end code, greatly improving operational efficiency.

Step 4: Ensure that the form data is successfully submitted

When the user

Related articles

How to ensure that the `siteId` parameter of the comment form in the AnQiCMS multi-site environment is correctly attributed?

## How to ensure that the `siteId` parameter of the comment form in the AnQiCMS multi-site environment belongs to the correct site?In today's ever-changing online world, many businesses and content operators are no longer satisfied with the operation of a single website.The demand for multi-brand strategies, niche market promotion, and even multilingual websites is growing increasingly, making multi-site management an indispensable capability.

2025-11-06

How to configure AnQiCMS form submission to return HTML or JSON formatted data?

As an experienced website operations expert, I know that every detail can affect user experience and operational efficiency.In AnQiCMS (AnQiCMS) such an enterprise-level content management system based on Go language, known for its efficiency and customizability, flexible control over the format of data returned after submitting a message form can undoubtedly bring more possibilities to content operation and user interaction.Today, let's delve into how to configure the comment form submission in AnQiCMS to return backend data in HTML or JSON format, as well as how this flexibility empowers our website operations

2025-11-06

When submitting the AnQiCMS message form, what are the basic required fields besides the custom fields?

As an experienced website operations expert, I know the importance of an efficient, user-friendly comment system for a corporate website.AnQiCMS (AnQiCMS) provides a solid foundation for building such a system with its high-performance architecture in Go language and flexible content management capabilities.In daily operations, the feedback form is a direct bridge between the website and visitors, not only collecting users' feedback and needs, but also an important source of potential business opportunities.Therefore, when designing and deploying the留言表单of 安企CMS, in addition to adding personalized custom fields according to business needs

2025-11-06

What is the default submit URL address for the AnQiCMS comment form?

As an experienced website operations expert, I am well aware of the importance of every detail for website user experience and data collection, especially in the most direct interaction between users and the website - form submission.Today, we will delve into the default submission URL address of the留言表单留言表单 form in AnQiCMS (安企CMS), and combine its functional features to provide you with a detailed analysis. Anqi CMS, with its efficient, customizable, and scalable features, has become an ideal choice for many small and medium-sized enterprises and content operation teams.

2025-11-06

How to integrate captcha functionality into the AnQiCMS comment form to prevent spam submissions?

In website operation, the message form is an important bridge for user interaction with the website.It bears the user's consultation, feedback, and even cooperation intentions. However, with the increasingly complex network environment, spam submission, which we commonly refer to as 'form flooding', has become a persistent problem for countless website operators.This junk information not only consumes server resources, but also seriously affects the data quality and user experience of the website.As an experienced website operations expert, I know that AnQiCMS (AnQiCMS) not only provides an efficient content management solution but also attaches great importance to website security. Today

2025-11-06

How does the website operator receive an email reminder after submitting the AnQiCMS message form?

In the daily work of website operation, promptly responding to user feedback is a key link in establishing trust and enhancing the brand image.How can you receive a reminder first time when a user submits a message form on your AnQiCMS website, so that you can respond quickly?Today, let's delve deeply into the email reminder mechanism of AnQiCMS to help you manage website comments efficiently.

2025-11-06

How to manage and export the submitted message form data in the AnQiCMS backend?

## Efficient management and export of Anqi CMS message form data: Your user feedback treasure trove In today's digital world, the voice of the user is one of the most valuable assets of a business.Whether it is to obtain potential customer information, collect product feedback, or listen to user suggestions, the message form is an important bridge of communication between the website and users.AnQiCMS (AnQiCMS) fully understands the importance of these data, and therefore provides an intuitive and efficient form data management and export function in the background, making your operation work twice as effective.

2025-11-06

What is the difference in the `Content` field (default form value) of AnQiCMS comment form under different input types?

AnQiCMS with its high efficiency and flexibility has become a powerful assistant for many enterprises and content operation teams.In the daily operation of the website, the message form serves as an important bridge for interaction between users and the website, and its functional design and user experience are crucial.Among them, the setting of the default value in the comment form, especially the performance difference of the `Content` field under different input types, is a topic of concern for many operators.

2025-11-06