Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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,我被困在了我想用自己制作的表格来完成的事情的最后一部分。 当从下拉列表中选择一个特定值时,将弹出4个比标准表单更多的名称字段。我不知道是否需要这些可选字段。填写表格后,表格将发送至电子邮件地址 HTML: PHP: 试试这个怎么样 <script> $('#typeTicket').on('change', function() { if ($(this).val() === "TeamTicket") { $("#extraNamen").show();

我被困在了我想用自己制作的表格来完成的事情的最后一部分。 当从下拉列表中选择一个特定值时,将弹出4个比标准表单更多的名称字段。我不知道是否需要这些可选字段。填写表格后,表格将发送至电子邮件地址

HTML:

PHP:


试试这个怎么样

<script>
$('#typeTicket').on('change', function() {
    if ($(this).val() === "TeamTicket") {
        $("#extraNamen").show();
        $("#extraNamen").attr("required",true);
    } else {
        $("#extraNamen").hide();
    }
});
</script>

$('#typeTicket')。在('change',function()上{
如果($(this.val()=“团队票证”){
$(“#extraname”).show();
$(“#extraname”).attr(“必需”,true);
}否则{
$(“#外部名称”).hide();
}
});
<script>
$('#typeTicket').on('change', function() {
    if ($(this).val() === "TeamTicket") {
        $("#extraNamen").show();
    } else {
        $("#extraNamen").hide();
    }
});
</script>
// Registration Form
    RegisterForm: function () {
        $("#register-form").submit(function (e) {
            e.preventDefault();
            var typeTicket = $("#typeTicket").val(),
                name = $("#name").val(),
                name1 = $("#name1").val(),
                name2 = $("#name2").val(),
                name3 = $("#name3").val(),
                name4 = $("#name4").val(),
                email = $("#email").val(),
                organisatie = $("#organisatie").val(),
                functie = $("#functie").val(),
                dataString = '&typeTicket=' + typeTicket + '&name=' + name + '&name1=' + name1 + '&name2=' + name2 + '&name3=' + name3 + '&name4=' + name4 + '&email=' + email + '&organisatie=' + organisatie + '&functie=' + functie;

            function isValidEmail(emailAddress) {
                var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
                return pattern.test(emailAddress);
            }

            if (isValidEmail(email) && (name.length > 1)) {
                $.ajax({
                    type: "POST",
                    url: "php/process.php",
                    data: dataString,
                    success: function () {
                        $('#register-form .form-notification').fadeIn(500);
                    }
                });
            } else {
                if (!isValidEmail(email)) {
                    $('input#email').addClass('not-valid');
                } else {
                    $('input#email').removeClass('not-valid');
                }
                if (name.length === 0) {
                    $('input#name').addClass('not-valid');
                } else {
                    $('input#name').removeClass('not-valid');
                }
            }
            return false;
        });
    },
$youremail = "Email adress hidden";

// Register Form
if ( isset($_POST['email']) && isset($_POST['name']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

    // Detect & Prevent Header Injections
    $test = "/(content-type|bcc:|cc:|to:)/i";
    foreach ( $_POST as $key => $val ) {
        if ( preg_match( $test, $val ) ) {
            exit;
        }
    }

    // Email Format
    $body  =    "New User Registration \n\n";
    $body .=    "========== \n\n";

    $body .=    "Ticket type:  $_POST[typeTicket] \n\n";

    if($_POST[typeTicket] == "TeamTicket") {
        $body .=    "Naam:  $_POST[name] \n\n";
        $body .=    "Naam:  $_POST[name1] \n\n";
        $body .=    "Naam:  $_POST[name2] \n\n";
        $body .=    "Naam:  $_POST[name3] \n\n";
        $body .=    "Naam:  $_POST[name4] \n\n";
    } else {
        $body .=    "Naam:  $_POST[name] \n\n";
    }

    $body .=    "Organisatie:  $_POST[organisatie] \n\n";
    $body .=    "Functie:  $_POST[functie] \n\n";

    $body .=    "Email:  $_POST[email] \n\n";

    //Send email
    mail( $youremail, "New User Registration", $body, "From:" . $_POST['email'] );
}
<script>
$('#typeTicket').on('change', function() {
    if ($(this).val() === "TeamTicket") {
        $("#extraNamen").show();
        $("#extraNamen").attr("required",true);
    } else {
        $("#extraNamen").hide();
    }
});
</script>