在Tpl表单中包含验证码

时间:2016-11-25 18:58:53

标签: javascript php captcha

您好我尝试在.Tpl表单中包含一个Captcha脚本但是如果我写了正确的电子邮件而没有填写验证码简单表单跳转验证码 表单看起来是单词,验证码显示数字。我尝试使用onsubmit ="返回checkform(this);"值=" {{$提交}} 但没什么好看的 有什么想法吗?

    <div class="generic-content-wrapper-styled">
<h3>{{$title}}</h3>

<p id="lostpass-desc">
{{$desc}}
</p>

<form action="lostpass" method="post" >
<div id="login-name-wrapper">
        <label for="login-name" id="label-login-name">{{$name}}</label>
        <input type="text" maxlength="60" name="login-name" id="login-name" value="" />
                <input type="submit" name="submit" id="lostpass-submit-button" onsubmit="return checkform(this);" value="{{$submit}}"/>
</div>
<!-- START CAPTCHA -->
<br>
<div class="capbox">

<div id="CaptchaDiv"></div>

<div class="capbox-inner">
Type the above number:<br>

<input type="hidden" id="txtCaptcha">
<input type="text" name="CaptchaInput" id="CaptchaInput" size="15"><br>

</div>
</div>
<br><br>
<!-- END CAPTCHA -->

<div id="login-extra-end"></div>
<div id="login-submit-end"></div>
</form>
<script type="text/javascript">

// Captcha Script

function checkform(theform){
var why = "";

if(theform.CaptchaInput.value == ""){
why += "- Please Enter CAPTCHA Code.\n";
}
if(theform.CaptchaInput.value != ""){
if(ValidCaptcha(theform.CaptchaInput.value) == false){
why += "- The CAPTCHA Code Does Not Match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}

var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';

var code = a + b + c + d + e;
document.getElementById("txtCaptcha").value = code;
document.getElementById("CaptchaDiv").innerHTML = code;

// Validate input against the generated number
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('CaptchaInput').value);
if (str1 == str2){
return true;
}else{
return false;
notice( t('No valid account found.') . EOL);
                        goaway(z_root());

}
}

// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}
</script>

</div>

0 个答案:

没有答案
相关问题