Modify the fields of the Dream custom form as required

Source: Internet
Author: User
Tags php file

The custom form function of Zhimeng allows you to easily create your own form function and collect users' messages, orders, and other information.

However, dedecms user-defined forms have a disadvantage. They do not have a verification function and allow empty forms to be submitted. As a result, the background displays a lot of empty data and cannot collect complete user information. Today, we will add a required content verification function to the dedecms custom form:

1. Modify diy_field_add.htm and add code around 24 lines.

Var necessary = theform. necessary [0]. checked? Theform. necessary [0]. value: theform. necessary [1]. value;

Replace the string, which is about 38 rows.

Replace

Revalue = "<field: "+ fieldname +" itemname = \ "" + itemname + "\" autofield = \ "1 \" type = \ "" + dtype + "\" isnull = \ "" + sisnull + "\" default = \ "" + vdefault + "\"";

Is

Revalue = "<field: "+ fieldname +" itemname = \ "" + itemname + "\" autofield = \ "1 \" type = \ "" + dtype + "\" isnull = \ "" + sisnull + "\" necessary = \ "" + necessary + "\" default = \ "" + vdefault + "\"";

2、diy_field_add.htm, after about 111 lines, add code

                     
 
      Required or not:
Prevent malicious form submission
        YesNo

3. Modify diy_field_edit.htm and add code around 18 lines.

Var necessary = theform. necessary [0]. checked? Theform. necessary [0]. value: theform. necessary [1]. value;

Replace the string, which is about 38 rows.

Replace

Revalue + = "isnull = \" "+ sisnull +" \ "default = \" "+ vdefault + "\"";

Is

Revalue + = "isnull = \" "+ sisnull +" \ "necessary = \" "+ necessary +" \ "default = \" "+ vdefault + "\"";

4、diy_field_edit.htm, add code after about 139 lines

             
 
Required or not:
Prevent malicious form submission
<Input name = "necessary" type = "radio" value = "true"GetAtt ('cessary') = 'true') echo "checked = '1'";?> Class = 'NP '/> is <input name = "necessary" type = "radio" value = "false"GetAtt ('necessary') = 'false' | $ ctag-> GetAtt ('necessary') = '') echo" checked = '1' ";?> Class = 'NP '/> No

5. Form submission:

Modify the plus/diy. Php file

Find $ addvar = $ addvalue = ''; and add the code above.

// Verify the required field $ row = $ dsql-> GetOne ("SELECT * FROM 'dede _ diyforms 'Where 'table' = '{$ diy-> table }'"); $ fieldset = $ row ['info']; require_once (DEDEINC. "/dedetag. class. php "); $ dtp = new DedeTagParse (); $ dtp-> SetNameSpace (" field "," "); $ dtp-> LoadSource ($ fieldset ); if (is_array ($ dtp-> CTags) {foreach ($ dtp-> CTags as $ tagid => $ ctag) {if ($ ctag-> GetAttribute ("necessary ") = 'true' & empty ($ {$ ctag-> GetName ()}) {show Msg ($ ctag-> GetAttribute ("itemname"). "cannot be blank! ",-1); exit ;}}}

6. This is basically done. Set parameters through the background field editing settings.
 

The above is a required method to modify the fields in the custom form of Zhimeng. I hope it will be helpful to dedecms website construction.

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.