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.