Wemeng dedecms custom form settings required tutorial

Source: Internet
Author: User

Method 1: modify the program source file.

1. Find the diy. Php file in the plus folder, edit it, and find the code around 40th lines:

$ Dede_fields = empty ($ dede_fields )? '': Trim ($ de_fields );
2. Under this line of code, add the following code and save the file:

// Add a required field for determination
If ($ required! = ''){
If (preg_match ('/,/', $ required )){
$ Requireds = explode (',', $ required );
Foreach ($ requireds as $ field ){
If ($ field = ''){
ShowMsg (','-1 ');
Exit ();
 }
 }
} Else {
If ($ required = ''){
ShowMsg (','-1 ');
Exit ();
 }
 }
 }
// End
3. Find the code in the created custom form:

<Form action = "/plus/diy. php" enctype = "multipart/form-data" method = "post">
4. Add the code below this line of code:

<Input type = "hidden" name = "required" value = "data field name, data field name"/>
Note that you need to modify this line of code and set the required items according to your form. For example, set "name" and "email" as required.

Add a new field-"form prompt text": name-"field name": name

Add a new field-"form prompt text": email-"field name": email

For example: <input type = "hidden" name = "required" value = "name, email"/>
5. After saving, the required item is set. When the user submits the form time and the system checks that the required item does not have any input content, the system will prompt "required content with the * Sign, please fill in correctly ".

Method 2: javascript script code for detection

1. Save the following code as a bitian. js file:

$ (Document). ready (function (){
// Verify
$ ('# Complain'). submit (function (){
If ($ ('# name'). val () = ""){
$ ('# Name'). focus ();
Alert ("the user name cannot be blank! ");
Return false;
}
If ($ ('# TEL'). val () = ""){
$ ('# Tel'). focus ();
Alert ("The contact number cannot be blank! ");
Return false;
}
If ($ ('# title'). val () = ""){
$ ('# Title'). focus ();
Alert ("title cannot be blank! ");
Return false;
}
If ($ ('# text'). val () = ""){
$ ('# Text'). focus ();
Alert ("The specific content cannot be blank! ");
Return false;
}
})
});
Reminder:

$ ('# Complain'). submit (function () // complain is the ID of the custom form. If the generated form does not exist, you can add it by yourself, that is, id = "complain"
If ($ ('# name '). val () = "") {$ ('# name '). focus (); // # name indicates the ID in the form to be verified. If you want to leave the user name blank, set the data field name of the user name in the background to name, the same below
2. Add the call code in the form template file:

<Script src = 'File path/js. Js' type = "text/javascript"> </script>
3. Save and regenerate the webpage!

Note: When copying code directly, punctuation marks must be kept in English.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.