How to retrieve and display custom fields in the AnQiCMS template for the website message form and ensure correct submission?

Calendar 👁️ 63

In Anqi CMS, adding and managing custom fields for the website's message form can not only help us collect more specific and targeted customer information, but also significantly improve the interactivity and data collection efficiency of the website.AnQi CMS, with its flexible content model and easy expandability, makes this process very convenient.

This article will guide you on how to obtain and display custom fields in the Anqi CMS template and ensure that these fields are correctly submitted.

Step 1: Define the custom message field in the Anqi CMS backend

Firstly, we need to add the required custom fields for the message function in the Anqi CMS backend management system.This is like designing questions for your form to ensure you can collect the information you want.

  1. Enter the website message management:Log in to the AnQi CMS backend, navigate to the "Function Management" menu, and then click "Website Message Management."}
  2. Add custom field:Here, you will see a button labeled 'Add Field' or similar. Click it to start defining new fields.
  3. Configure field properties:
    • Parameter name:This is the field name displayed on the back end, for example 'Your industry', 'Product type'.
    • Field Name (FieldName):This is the unique identifier for the field referenced in the template, it is usually recommended to use letters, such asyourIndustry/productType.Be sure to remember this name, it will be used in the template.
    • Field type:The Anqi CMS provides various field types to meet different input requirements:
      • Single-line text (text):Suitable for brief information such as names, phone numbers, and email addresses.
      • Number (number):Enter only numbers, such as quantity, budget.
      • Multiline text (textarea):Suitable for longer content, such as specific requirements, message details.
      • Single choice (radio):Users can only select one option, such as gender, agree to the agreement.
      • Multiple choice (checkbox):Users can select multiple options, such as services of interest.
      • Drop-down selection (select):Select an option from the dropdown menu.
    • Mandatory?:Tick as required; if ticked, this field must be filled out when submitting the form.
    • Default:Provide a default value or placeholder text for the field. This is where you define the options for radio buttons, checkboxes, and dropdowns, one per line.

After defining the field, save your settings. Now, these custom fields are ready for use in the template.

Step two: Retrieve and render the custom fields in the template.

Next, we will modify the Anqi CMS template file, displaying these custom fields in the website's front-end message form. Usually, the message form is located in your template directory.guestbook/index.htmlfile.

The template used by Anqi CMS is similar to the Django template engine syntax. To get the custom fields of the comment form, we need to use the built-inguestbook.

  1. Find the comment form template file:In your template directory, find the HTML file used to display the comment form (for example:)template/您的模板名/guestbook/index.html)

  2. UseguestbookLabel field acquisition:within the form's<body>or at the appropriate location, use{% guestbook fields %}tags to retrieve all the defined message fields.fieldsThe variable will be an array object containing all field information.

    <form method="post" action="/guestbook.html">
        {# 这里将用于展示默认的留言字段和您自定义的字段 #}
        {% 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 }}" name="{{ item.FieldName }}" id="{{ item.FieldName }}"
                           {% if item.Required %}required{% endif %}
                           placeholder="{{ item.Content }}" class="form-control">
                    {% elif item.Type == "textarea" %}
                    <textarea name="{{ item.FieldName }}" id="{{ 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" name="{{ item.FieldName }}" value="{{ val }}" id="{{ item.FieldName }}-{{ loop.index }}"
                               {% if item.Required %}required{% endif %} class="form-check-input">
                        <label for="{{ item.FieldName }}-{{ loop.index }}" class="form-check-label">{{ val }}</label>
                        {%- endfor %}
                    {% elif item.Type == "checkbox" %}
                        {%- for val in item.Items %}
                        <input type="checkbox" name="{{ item.FieldName }}[]" value="{{ val }}" id="{{ item.FieldName }}-{{ loop.index }}"
                               {% if item.Required %}required{% endif %} class="form-check-input">
                        <label for="{{ item.FieldName }}-{{ loop.index }}" class="form-check-label">{{ val }}</label>
                        {%- endfor %}
                    {% elif item.Type == "select" %}
                    <select name="{{ item.FieldName }}" id="{{ 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 %}
        {% endguestbook %}
    
        {# 假设您还会有一些固定的留言字段,例如联系方式和留言内容 #}
        <div class="form-group">
            <label for="user_name">您的称呼 <span class="text-danger">*</span></label>
            <input type="text" name="user_name" id="user_name" required placeholder="请填写您的称呼" class="form-control">
        </div>
        <div class="form-group">
            <label for="contact">联系方式 <span class="text-danger">*</span></label>
            <input type="text" name="contact" id="contact" required placeholder="手机号/邮箱/微信" class="form-control">
        </div>
        <div class="form-group">
            <label for="content">留言内容 <span class="text-danger">*</span></label>
            <textarea name="content" id="content" required placeholder="请输入您的留言内容" rows="6" class="form-control"></textarea>
        </div>
    
        {# 提交按钮 #}
        <div class="form-group">
            <button type="submit" class="btn btn-primary">提交留言</button>
            <button type="reset" class="btn btn-secondary">重置</button>
        </div>
    </form>
    

    Code description:

    • {% guestbook fields %}It will take all custom fields set in the background asfieldsan array to provide to the template. *

Related articles

How to display the comment list of an article in AnQiCMS template, including multi-level replies and review status indicators?

In Anqi CMS, let your article page not only be a display of content, but also an active communication platform, and the comment feature is the bridge connecting content with readers.Understanding how to flexibly display an article's comment list in a template, including multi-level replies and clear review status indicators, is crucial for building an interactive website. ### The foundation of comment functionality: Ensure backend configuration is ready Before delving into template code, we first need to confirm that the comment feature is enabled in the AnQi CMS backend.

2025-11-07

How to configure the pseudo-static URL rule in AnQiCMS to optimize the display path and SEO friendliness?

In website operation, the URL is not only the address of the page content, but also an important part of search engine understanding, user identification, and brand building.A clear and meaningful URL structure, known as "pseudo-static" or "staticized" URL, is crucial for improving the SEO performance and user experience of a website.AnQiCMS is a content management system that focuses on SEO-friendliness and provides flexible and diverse static URL configuration features, helping us optimize the display path of content better.

2025-11-07

How to perform simple arithmetic operations (+ - * /) and display the results in AnQiCMS template?

In AnQiCMS templates, we often need to display website content and data.But sometimes, we not only need to display stored data, but also need to process this data in some simple ways, such as calculating the total price of goods, statistics page loading progress percentage, or adding a certain number of values, etc.

2025-11-07

How to use the `default` filter to set a default display value for possibly empty variables?

In website content management, we often encounter a situation where a certain data variable may not have a value on some pages or under certain conditions, that is, "empty".If the template directly outputs these blank variables, ugly gaps will appear on the page, which not only affects the aesthetics but may also confuse the visitor.In order to avoid such embarrassment, AnQi CMS provides a very practical tool - the `default` filter, which can help us set a graceful default display value for these variables that may be empty.

2025-11-07

How does AnQiCMS implement anti-crawling interference code through built-in features to protect the display of original content on the front end?

Today, as digital content becomes a core asset, how to effectively protect original content from malicious collection and misuse has become a common challenge for website operators and content creators.Hardly created articles, product descriptions, in a moment may appear on other websites, not only dilute the value of original content, but may also have a negative impact on the search engine rankings of websites.AnQiCMS (AnQiCMS) is fully aware of this pain point and therefore built-in anti-crawling interference code function at the initial stage of system design, aiming to build a clever and sturdy barrier for the display of original content on the front end.

2025-11-07

How to correctly render Markdown content in AnQiCMS and support the display of mathematical formulas and flow charts?

In modern content management, providing rich and structured content has become the key to improving user experience and information delivery efficiency.Especially for technical blogs, product documents, or data analysis reports, the ability to visually display code, mathematical formulas, and complex flowcharts undoubtedly makes the content more attractive and readable.AnQiCMS as an efficient and customizable enterprise-level content management system fully understands this requirement and provides comprehensive Markdown support, allowing you to easily achieve these advanced content displays.

2025-11-07

How to insert custom structured data using `Ld` tags on AnQiCMS pages to enhance search engine display effects?

When building and optimizing a website, we always hope to allow search engines to deeply understand the content of our pages so that we can achieve better display effects in search results.Structured data, especially structured data presented in JSON-LD format, is an important tool to achieve this goal.AnQiCMS (AnQiCMS) is a content management system that focuses on SEO optimization and provides flexible and powerful support for inserting custom JSON-LD.

2025-11-07

How does AnQiCMS implement different content display and adaptation for PC and mobile devices through the template directory structure?

In the era when mobile internet occupies a dominant position, ensuring that website content can be perfectly displayed on different devices is a core issue that every website operator is very concerned about.AnQiCMS provides an extremely flexible and powerful solution in this aspect, allowing us to easily provide optimized display and interaction experience for users on both PC and mobile terminals.The key to AnQiCMS achieving content adaptation for PC and mobile ends lies in its carefully designed template directory structure and flexible website mode selection.

2025-11-07