0

我正在制作一个简单的表单,用户可以在其中提交视频以及他们的电子邮件地址。我想让这个人在填写电子邮件并保存视频之前无法提交表格。

视频部分正在运行,但是当我使用空电子邮件进行测试时,它似乎仍然可以提交。代码如下,现场版在http://www.atlas-china.com/record-your-multi-lingual-abilties/

非常感谢帮助!

// Global variable to hold player's reference.
var _Nimbb;

// Global variable to hold the guid of the recorded video.
var _Guid = "";

// Event: Nimbb Player has been initialized and is ready.
function Nimbb_initCompleted(idPlayer) {
    // Get a reference to the player since it was successfully created.
    _Nimbb = document[idPlayer];
}

// Event: the video was saved.
function Nimbb_videoSaved(idPlayer) {
    _Guid = _Nimbb.getGuid();
}

jQuery(document).ready(function ($) {

    // Get the data from the form.  Check that everything is completed.
    $('#video_submit').click(function (e) {

        var email = document.getElementById("email").value;
        var video_title = document.getElementById("video_title").value;
        var form = document.myForm;

        // Make sure the email is specified.
        if (email.value == "") {
            alert("Please enter your email to proceed.");
            return;
        }

        // Verify that the video is not currently recording.
        if (_Nimbb.getState() == "recording") {
            alert("The video is being recorded. Please wait.");
            return;
        }

        // Check that video has been recorded.
        if (_Guid == "") {
            alert("You did not save the video.  Click save.");
            return;
        }

        // Set the guid as hidden parameter.
        form.guid.value = _Guid;

        var dataString = 'email=' + email + '&guid=' + _Guid + '&video_title=' + video_title;
        //alert (dataString);return false;  
        $.ajax({
            type: "POST",
            url: "<?php echo get_template_directory_uri();?>/send.php",
            data: dataString,
            success: function () {
                $('#contact_form').html("<div id='message'></div>");
                $('#message').html("<h2>Contact Form Submitted!</h2>")
                    .append("<p>We will be in touch soon.</p>")
                    .hide()
            }
        });
        document.forms["myForm"].submit();
    });
});
4

2 回答 2

0

当您从该处理函数返回时,浏览器将继续执行“提交”事件的正常行为,即提交表单。

您可以将“中止”返回语句更改为

return false;
于 2013-10-08T13:27:56.940 回答
0

查看您的实时网站后...

email = "" // Empty string

然而

email.value = undefined 

尝试将您的代码更改为

if (email === "") {
    alert("Please enter your email to proceed.");
    return;
}

我假设您错误地执行了.value两次,因为您的代码前面有以下行

var email = document.getElementById("email").value;
于 2013-10-08T14:26:10.657 回答