我第一次尝试使用 reCaptcha,这是我到目前为止编写的代码,但它似乎不起作用。
这是我的html表单:
<form method="post" action=''>
<cfoutput>
<input type="hidden" name="isPost" value="1" />
First Name: <input type="text" name="firstname" placeholder="First name" required><br />
Last Name: <input type="text" name="lastname" placeholder="Last name" required><br />
Email: <input type="email" name="email" placeholder="example@email.com" required><br />
Zip Code: <input id="zip" type="text" pattern="[0-9]{5}" name="zipcodex" placeholder="ex. 01234" required /><br />
Home Phone: <input type="tel" pattern='[0-9]{10}' name="homephone" placeholder="ex. 3335551234" required><br />
Cell Phone: <input type="tel" pattern='[0-9]{10}' name="cellphone" value="#cellphone#" placeholder="ex. 9990001234"><br />
My Interest
<select class="interestOption" name="Formprocedure" id="procedure" required >
<option selected="selected" disabled="disabled" value="">My Interest</option>
<cfloop query="procedurefinder"><option <cfif procedureid eq Formprocedure>selected="selected" </cfif>title="#procedurename#" value="#procedureid#">#left(procedurename,20)#</option>
</cfloop>
</select><br />
<textarea name="comments" cols="50" rows="5" placeholder="Please enter any additional comments"></textarea><br />
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=6LdUMuISAAAAA********mMK5cbR1pm1AG4WV">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=6LdUMuISAAAAAMi**************mMK5cbR1pm1AG4WV"
height="50" width="400" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="0">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<br />
<button id="submit" onclick="SubmitForm();">Submit</button>
</cfoutput>
</form>
这是我的 JS 代码:
<script type="text/javascript">
function SubmitForm(){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST",'http://www.google.com/recaptcha/api/verify',true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
params ="'6LdUMuISAAAAAMi4iDZ1sIuEmMK5cbR1pm1AG4WV','www.newimagespecialists.com','"+Recaptcha.get_response()+"','"+Recaptcha.get_challenge+"'";
xmlHttp.send(params);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if(xmlHttp.status == 200){
form.submit();
}else{
return false;
}
}
}
}
</script>
这是我从萤火虫得到的回应:
Parameters application/x-www-form-urlencoded
'6LdUMuISAA1sIuE... =typeof RecaptchaState?null:RecaptchaState.challenge}'
Source
'6LdUMAA*******IuEmMAG4WV','www.example.com','fitsesq Accord','function (){return"undefined"==typeof RecaptchaState?null:RecaptchaState.challenge}'
我的问题是我真的不明白我的代码哪里有错误,以及为什么我的表单继续提交?任何人都可以指出我在哪里犯了错误?