On website operation, the message form is an important channel for interacting with users and collecting valuable information.To ensure that we can collect enough complete and useful data, such as users' contact information or specific needs, it is particularly important to set some fields in the form as 'mandatory items'.As an experienced website operation expert, I will guide you to deeply understand how to easily achieve this goal in AnQiCMS, making your留言表单留言表单 more intelligent and efficient.

Anqi CMS Message Form Feature Overview

AnQiCMS as an efficient enterprise-level content management system fully considered various operation needs from the beginning of its design.Its message feature not only allows users to submit information, but also supports flexible custom fields.This means you can add various fields such as name, phone, email, and specific requirement description according to your business scenario.These custom fields are the core of being able to set 'required'.From the AnQiCMS update log, we can see that as early asv2.0.0-alpha3Version has already added support for online comments and custom comment fields, laying the foundation for our flexible configuration.

Core steps: Set the field as required in the background.

Set a certain field in the AnQiCMS message form to be required. The entire process is intuitive and easy to operate. You do not need to write any code, just perform a few simple configurations in the background management interface:

  1. Log in to the AnQiCMS backendFirst, log in to the AnQiCMS backend management system using your administrator account and password.
  2. Navigate to feature management: Find and click on the 'Function Management' item in the left function menu.Here is a collection of many practical tools for website operation, including the main topic of today - "Website Message Management".
  3. Enter the website message managementIn the sub-menu of 'Function Management', click on 'Website Message Management'.Generally, this section displays all submitted comments and also provides access to the comment form fields management.
  4. Manage message fieldsOn the website message management page, you will find a section for managing custom message fields.Here is a list of all custom fields currently in your form.You can choose to edit an existing field or click 'Add new field' to create a brand new one.
  5. Set the field as requiredWhether editing an existing field or creating a new one, you will see an option named 'Mandatory' in the field configuration interface.This option is usually presented in the form of a checkbox or toggle.
    • To set this field as required, you just needtick or enablethis 'Is Required' option.
    • The underlying mechanism of AnQiCMS will automatically check whether this field is empty when you submit the form data.
  6. Save and take effectAfter completing the settings for 'Required', be sure to click the 'Save' or 'Submit' button at the bottom of the page.This will take effect and be reflected in the front desk message form.

By following these steps, you have successfully set the specified form field as required in the AnQiCMS backend.

How does the front-end template respond to the required setting?

The elegance of AnQiCMS lies in its highly collaborative front and back ends.How does the front-end template perceive and display the change after marking a field as required in the background?This mainly depends on the provided by AnQiCMSguestbooktags and theirRequiredProperty.

In the template file,guestbookThe label is used to loop through the fields of the comment form. Each field in the template can be accessed through aitemvariable, and thisitemvariable containsName(Form name),FieldName(Form variable),Type(Form type) information, including the most importantRequiredproperties. When you set a field to required in the background, its correspondingitem.Requiredvalue will be displayed on the front-end templatetrue.

Template developers usually write code like this to dynamically generate form items:

<form method="post" action="/guestbook.html">
{% guestbook fields %}
    {% for item in fields %}
    <div>
        <label>{{item.Name}}</label>
        <div>
            {% if item.Type == "text" or 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>
            {# 其他字段类型如radio, checkbox, select 的处理类似 #}
            {% endif %}
        </div>
    </div>
    {% endfor %}
    {# 提交按钮等 #}
    <button type="submit">提交留言</button>
</form>

The key to this code is{% if item.Required %}required lay-verify="required"{% endif %}. It checks if the current field is set as required, and if so, it will automaticallyinputortextareaAdd HTML5 to the form elementsrequiredthe attributes as welllay-verify="required"Such front-end validation markers (this is usually used for client-side validation in front-end frameworks like Layui).This way, before the user submits the form, the browser will prompt them to fill in this required field, greatly enhancing the user experience and ensuring the integrity of the data.

Actual operation and precautions

Setting the comment form field as required not only improves user experience, but also, by clearly informing users which information is necessary, it can avoid repeated submissions due to missing information, and can significantly improve the quality of the collected data.This means you will obtain more effective and reliable customer leads or feedback, providing a solid foundation for subsequent operational decisions.

The AnQiCMS Go backend will also perform server-side validation on required fields upon receiving form submission, even if the frontend validation is bypassed, the backend can still ensure the integrity of the data, thereby further ensuring data security and the correctness of business logic.

By using AnQiCMS's powerful and flexible backend configuration in conjunction with the front-end template, you can easily build a message form that meets your business needs and efficiently collect key information.


Frequently Asked Questions (FAQ)

Q1: After I set the field as required in the background, why does the form on the front end not display the required asterisk or not enforce mandatory filling?A1: This is usually due to your front-end template not being handled correctlyguestbookin the tagitem.Requiredproperty caused. Please check your feedback form template (usuallyguestbook/index.html), make sure to include similar fields when rendering form fields{% if item.Required %}required{% endif %}The code snippet to dynamically add HTML when a field is requiredrequiredproperty. If your website uses front-end frameworks like Layui, you also need to make surelay-verify="required"The validation mark has also been added correctly.

Q2: Can the default message fields of AnQiCMS (such as "Username", "Contact Information", "Message Content") be set as non-mandatory?A2: The AnQiCMS documentation mainly demonstrates the flexibility of custom fields.For the default message fields, they are usually designed as core information and are required by default to ensure the availability of basic messaging functions.If you wish to modify the required status of these default fields, this may not be directly provided through the backend interface options, but rather requires deeper template or system configuration adjustments, or through the use of custom fields to replace the default fields.Suggest you check the background "website message management" settings or consider using custom fields as a replacement.

Q3: After setting the required field, if the user submits without filling it in, what kind of prompt will there be?A3: If your front-end template has been correctly handledrequiredProperty, when a user tries to submit a form without filling in required fields, modern browsers will display built-in prompts according to the HTML5 specification (such as “Please fill in this field”).If your website integrates front-end frameworks such as Layui, you usually have more beautiful and customizable prompt styles.In addition, the backend of AnQiCMS will also perform a second verification, and if the required items are indeed missing, it will usually return an error message to the user.