The method of weaving dream dedecms website to add dede template to custom form with its own verification code.
Sometimes, we need to add a verification code to the custom form of the dede website to prevent malicious filling of the form submission.
We can do this in the following way:
First, we need to find the file /plus/diy.php
Introduce the file in the header:
require_once(DEDEINC.'/membermodel.cls.php');
then find
elseif($do == 2)
{ add code block here
// verification code verification
$ download = GetCkVdValue ();
if(preg_match("/1/",$safe_gdopen)){
if(strtolower($vdcode)!=$svali || $svali=='')
{
ResetVdValue ();
ShowMsg('Verification code error!', '-1');
exit();
}
}
Save the file after making changes.
Step 2: Insert code block in custom form static page using captcha
<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="Can't see? Click to replace" src="/include/ vdimgck.php"/> Can't see clearly?
In this static page, you have to reference JQuery
Add the JS code block
<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>
Ok, let's try it now, is it possible to submit the verification code? A simple dedecms custom form dede template comes with its own verification code function.
Generally, you will encounter an error on line 172, because there is one less "}", just add one to line 172 and it will be OK.