Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript验证码验证部分返回整个表单,而不是继续_Javascript_Php_Jquery_Html_Forms - Fatal编程技术网

javascript验证码验证部分返回整个表单,而不是继续

javascript验证码验证部分返回整个表单,而不是继续,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,我使用的是来自的联系人表单,我试图实现一个基本的数学验证码。但是,当我提交表单时,无论验证码是正确的还是错误的,它都会弹出错误验证码的错误消息,而不是提交表单 这部分代码是我编辑的: function submitForm() { var contactForm = $(this); if ( !$('#senderName').val() || !$('#senderEmail').val() || !$('#message').val() ) { $('#i

我使用的是来自的联系人表单,我试图实现一个基本的数学验证码。但是,当我提交表单时,无论验证码是正确的还是错误的,它都会弹出错误验证码的错误消息,而不是提交表单

这部分代码是我编辑的:

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&#39;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) {
<label id="captcha" for="captcha"></label>
为此:

if($('#captcha').val() != captcha_c) {
此外,您的标签id与输入的id相同,因此请更改此项:

if(('#captcha') != captcha_c) {
<label id="captcha" for="captcha"></label>


您忘记了
$
符号在
(“#验证码”)

if((“#captcha')!=captcha_c)

中,您可以使用console.log打印$(“#captcha').val()和captcha_c吗?我该怎么做?我知道在php中我可以使用
var_dump()
,但在javascriptadd
console.log($('captcha').val())中我是全新的;控制台日志(验证码c)
,您将在浏览器的控制台中看到该值。