elated.com의 문의 양식을 사용 중입니다. 기본 수학 captcha를 구현하려고합니다. 그러나 양식을 제출할 때 captcha가 올 바르고 잘못 되었든간에 양식을 제출하는 대신 잘못된 captcha 오류 메시지가 나타납니다.javascript captcha 유효성 검사 부분
코드의이 부분은 내가 편집 한 하나입니다
function submitForm() {
var contactForm = $(this);
if (!$('#senderName').val() || !$('#senderEmail').val() || !$('#message').val()) {
$('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
contactForm.fadeOut().delay(messageDelay).fadeIn();
}
// this is the part of the code I added the captcha verification.
if(('#captcha') != captcha_c) {
$("#captchaError").slideDown(500);
$("#captchaError").delay(messageDelay).slideUp(500);
} else {
$('#sendingMessage').fadeIn();
contactForm.fadeOut();
$.ajax({
url: contactForm.attr('action') + "?ajax=true",
type: contactForm.attr('method'),
data: contactForm.serialize(),
success: submitFinished
});
}
return false;
}
HTML 양식 : 나는 주석 부분을 제거하면 형태가 작동하고 이메일을 보내 진행되는
<form id="contactForm" action="processForm.php" method="post">
<h2>Send us an email...</h2>
<ul>
<li>
<label for="senderName">Your Name</label>
<input id="senderName" maxlength="40" name="senderName" placeholder="Please type your name" required="required" type="text" />
</li>
<li>
<label for="senderEmail">Your Email Address</label>
<input id="senderEmail" maxlength="50" name="senderEmail" placeholder="Please type your email address" required="required" type="email" />
</li>
<li>
<label for="message" style="padding-top: .5em;">Your Message</label>
<textarea id="message" cols="80" maxlength="10000" name="message" placeholder="Please type your message" required="required" rows="10"></textarea>
</li>
<li>
<label id="captcha" for="captcha"></label>
<input id="captcha" name="captcha" placeholder="Enter the captcha" required="required" type="text" />
<script type="text/javascript">
generate_captcha('captcha');
</script>
</li>
</ul>
<div id="formButtons">
<input id="sendMessage" name="sendMessage" type="submit" value="Send Email" />
<input id="cancel" name="cancel" type="button" value="Cancel" />
</div>
</form>
<div id="sendingMessage" class="statusMessage">
<p>Sending your message. Please wait...</p>
</div>
<div id="successMessage" class="statusMessage">
<p>Thanks for sending your message! We'll get back to you shortly.</p>
</div>
<div id="failureMessage" class="statusMessage">
<p>There was a problem sending your message. Please try again.</p>
</div>
<div id="incompleteMessage" class="statusMessage">
<p>Please complete all the fields in the form before sending.</p>
</div>
<div id="captchaError" class="statusMessage">
<p>Are you sure about your calculations?</p>
</div>
, 어디에서 javascript 부분에서 잘못 되었습니까? 이것에
if(('#captcha') != captcha_c) {
:
if($('#captcha').val() != captcha_c) {
은 또한 당신이 당신의 입력 때문에이를 변경 등의 라벨에 대해 동일한 ID를 가지고 여기
는 working live example
이 제안 된 코드로 변경되었지만 작동하지 않음 – Nescafe