Home >CMS Tutorial >DEDECMS >Fixed the problem of adding verification code to Dede custom form
How to add a dede template to the custom form on the dedecms website with its own verification code.
Sometimes, we need to add a verification code to the custom form on the dede website to prevent malicious filling in and submission of the form.
# We can use the following methods to achieve: (Recommended learning: CMS )
## 首 First, we want to find/plus/diy .php fileIntroduce the file in the header:
require_once(DEDEINC.'/membermodel.cls.php');Then find
elseif($do == 2) { 在这个地方加入代码块 //验证码验证 $svali = GetCkVdValue(); if(preg_match("/1/",$safe_gdopen)){ if(strtolower($vdcode)!=$svali || $svali=='') { ResetVdValue(); ShowMsg('验证码错误!', '-1'); exit(); } }and save the file after modification.
Second step: Insert the code block into the custom form static page using the verification code
<input type="text" class="intxt w200" style="width: 50px; text-transform: uppercase;" id="vdcode" name="vdcode" class="code"/> <img id="vdimgck" align="absmiddle" onclick="this.src=this.src+'?'" style="cursor: pointer;" alt="看不清?点击更换" src="/include/vdimgck.php"/> 看不清?
You must also reference JQuery# in this static page
##Add the JS code block again<script type="text/javascript">
$ = jQuery;
function changeAuthCode() {
var num = new Date().getTime();
var rand = Math.round(Math.random() * 10000);
num = num + rand;
$('#ver_code').css('visibility','visible');
if ($("#vdimgck")[0]) {
$("#vdimgck")[0].src = "../include/vdimgck.php?tag=" + num;
}
return false;
}
</script>
Okay, give it a try now, is it possible to submit the verification code? A simple dedecms custom form dede template comes with the function of verification code.
Generally you will encounter an error on line 172 because there is a missing "}". Just add one on line 172. OK.
The above is the detailed content of Fixed the problem of adding verification code to Dede custom form. For more information, please follow other related articles on the PHP Chinese website!