This code sends empty values ​​to the table. How can I fix this

advertisements

My code is supposed to validate the form and send the information to a php page. I know the validation and php works, but for some reason, it is inserting blanks into the table. How can I fix this? I think its the ajax part that is not working. While it does send to the php page, it sends empty variables. How can I fix this?

$(function() {
    // Setup form validation on the #register-form element
    $("#val2").validate({
        // Specify the validation rules
        rules: {
            Name: {
                required: true,
                maxlength: 50
            },
            telephone: {
                required: true,
                number: true
            },
            Email: {
                required: true,
                email: true
            },
            message: {
                required: true,
                minlength: 30
            },
        },

        // Specify the validation error messages
        messages: {
            Name: {
                required: "Please enter your name",
                maxlength: "Please Keep your name under 50 characters"
            },
            telephone: {
                required: "Please enter your number",
                number: "Please enter a valid number"
            },
            message: {
                required: "Please provide a password",
                minlength: "Your message must be at least 30 characters long"
            },
            Email: "Please enter a valid email address",
        },

        submitHandler: function(form) {
            debugger;
            var name = form.Name.value;
            var email = form.Email.value;
            var number = form.telephone.value;
            var message = form.message.value;
            var product = form.product.value;

            $.ajax({
                type: "POST",
                url: 'process.php',
                data: name,
                email,
                number,
                message,
                product,
                dataType: 'html'
            });
        }
    });
}); 

You're only passing 'name' in the data field. Change the ajax call to:

$.ajax({
    type: "POST",
    url: 'process.php',
    data: {
        name : name,
        email : email,
        number : number,
        message : message,
        product : product
    },
    dataType: 'html'
});