变量没有用ajax传递帖子

时间:2014-01-13 22:23:09

标签: javascript php jquery ajax

我尝试过几种不同的方法,并坚持这一点。我有一个模态的形式,滑出来订购一些零件。提交表单后,它会通过javascript测试然后发布到php页面发送电子邮件给公司订购部件。我有它工作除了两件事。单选按钮(三个)显示未识别,“城市”文本空白。以下是代码,页面链接为http://arhcycles.com/new/drag-specialties.php

形式

//declare our variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zipcode = $_POST['zipcode'];
    $supplier1 = $_POST['supplier1'];
    $supplier2 = $_POST['supplier2'];
    $supplier3 = $_POST['supplier3'];
    $supplier4 = $_POST['supplier4'];
    $qty1 = $_POST['qty1'];
    $qty2 = $_POST['qty2'];
    $qty3 = $_POST['qty3'];
    $qty4 = $_POST['qty4'];
    $p_number1 = $_POST['p_number1'];
    $p_number2 = $_POST['p_number2'];
    $p_number3 = $_POST['p_number3'];
    $p_number4 = $_POST['p_number4'];
    $message = nl2br($_POST['message']);
    //get todays date
    $todayis = date("l, F j, Y, g:i a") ;
    //set a title for the message
    $subject = "Parts Order From ARH Cycles";
    $body_message = '<html><body style="color:#FFFFFF; background-color: #850000">';
    $body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
    $body_message .= '<tr style="background: #850000;"><td><strong>From:</strong>     </td><td>'.$name.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Email:</strong> </td><td>'.$email.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Phone:</strong> </td><td>'.$phone.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Address:</strong> </td><td>'.$address .'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>City:</strong> </td><td>'.$city.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>State:</strong> </td><td>'.$state.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Zipcode:</strong> </td><td>'.$zipcode .'</td></tr>';
    $body_message .= '</table>';
    $body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier1.'</td><td><strong>Quanity:</strong> </td><td>'.$qty1.'</td><td><strong>Part Number:</strong></td><td>'.$p_number1.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td> ' .$supplier2.'</td><td><strong>Quanity:</strong> </td><td>'.$qty2.'</td><td><strong>Part Number:</strong></td><td>'.$p_number2.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier3.'</td><td><strong>Quanity:</strong> </td><td>'.$qty3.'</td><td><strong>Part Number:</strong></td><td>'.$p_number3.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier4 .'</td><td><strong>Quanity:</strong> </td><td>'.$qty4.'</td><td><strong>Part Number:</strong></td><td>'.$p_number4.'</td></tr>';
    $body_message .= '</table>';
    $body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
    $body_message .= '<tr style="background: #850000;"><td colspan="3"><strong>Message:</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td rowspan="3"colspan="3">' .$message .'</td></tr>';
    $body_message .= '</table>';
    $body_message .= '</body></html>'; 
    $headers = "From: " .$email . "r\n" ;
    $headers .= "Reply-To: ".$email . "\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";                   


    //put your email address here
    mail("email@yourdomain.com, $email", $subject, $body_message, $headers);
    ?>
   <!--Display a thankyou message in the callback -->
   <div id="mail_response">
   <h3>Thank you for your order&nbsp<?php echo $name ?>!</h3><br />
   <p>We will be calling to verify your order and take payment.</p><br />
   <p>Please look over your order above and call (281) 970-1200 if incorrect.</p><br />
   <h5>Message sent on: </h5>
   <p><?php echo $todayis ?></p>

的JavaScript

    $(document).ready(function(){
//function for contact form dropdown
 function contact() {
    if ($("#contactForm").is(":hidden")){
        $("#contactForm").slideDown("slow");
        $("#backgroundPopup").css({"opacity": "0.7"});
        $("#backgroundPopup").fadeIn("slow"); 
     }
     else{
        $("#contactForm").slideUp("slow");
        $("#backgroundPopup").fadeOut("slow");  
    }
        }

    //run contact form when any contact link is clicked
$(".contact").click(function(){contact()});

//animation for same page links #
$('a[href*=#]').each(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname
    && this.hash.replace(/#/,'') ) {
      var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
      var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
        if ($(this.hash).length) {
            $(this).click(function(event) {
                var targetOffset = $(this.hash).offset().top;
                var target = this.hash;
                event.preventDefault();            
                $('html, body').animate({scrollTop: targetOffset}, 500);
                return false;
            });
        }
    }
    });



    //submission scripts
    $('.contactForm').submit( function(){
    //statements to validate the form   
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var email = document.getElementById('e-mail');
    if (!filter.test(email.value)) {
        $('.email-missing').show();
    } else {$('.email-missing').hide();}
    if (document.cform.name.value == "") {
        $('.name-missing').show();
    } else {$('.name-missing').hide();} 
    if (document.cform.message.value == "") {
        $('.message-missing').show();
    } else {$('.message-missing').hide();}      
    if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.phone.value == "")){
        return false;
    } 

    if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.phone.value != "")) {
        //hide the form
        $('.contactForm').hide();

        //show the loading bar
        $('.loader').append($('.bar'));
        $('.bar').css({display:'block'});

        //send the ajax request
        $.post('includes/mail.php',{name:$('#name').val(),

    email:$('#e-mail').val(),

    phone:$('#phone').val(),
                                    address:$('#address').val(),
                                    city:$('#city').val(),
                                    state:$('#state').val(),
                                    zipcode:$('#zipcode').val(),
                                    supplier1:$('#supplier1').val(),
                                    qty1:$('#qty1').val(),
                                    p_number1:$('#p_number1').val(),
                                    supplier2:$('#supplier2').val(),
                                    qty2:$('#qty2').val(),
                                    p_number2:$('#p_number2').val(),
                                    supplier3:$('#supplier3').val(),
                                    qty3:$('#qty3').val(),
                                    p_number3:$('#p_number3').val(),
                                    supplier4:$('#supplier4').val(),
                                    qty4:$('#qty4').val(),
                                    p_number4:$('#p_number4').val(),
                                    message:$('#message').val()},

        //return the data
        function(data){
          //hide the graphic
          $('.bar').css({display:'none'});
          $('.loader').append(data);
        });

        //waits 2000, then closes the form and fades out
        setTimeout('$("#backgroundPopup").fadeOut("slow"); $("#contactForm").slideUp("slow")', 4000);

        //stay on the page
        return false;
    } 
    });
//only need force for IE6  
$("#backgroundPopup").css({  
    "height": document.documentElement.clientHeight 
});  
    });

PHP

   <?php
    //declare our variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zipcode = $_POST['zipcode'];
    $supplier1 = $_POST['supplier1'];
    $supplier2 = $_POST['supplier2'];
    $supplier3 = $_POST['supplier3'];
    $supplier4 = $_POST['supplier4'];
    $qty1 = $_POST['qty1'];
    $qty2 = $_POST['qty2'];
    $qty3 = $_POST['qty3'];
    $qty4 = $_POST['qty4'];
    $p_number1 = $_POST['p_number1'];
    $p_number2 = $_POST['p_number2'];
    $p_number3 = $_POST['p_number3'];
    $p_number4 = $_POST['p_number4'];
    $message = nl2br($_POST['message']);
    //get todays date
    $todayis = date("l, F j, Y, g:i a") ;
    //set a title for the message
    $subject = "Parts Order From ARH Cycles";
    $body_message = '<html><body style="color:#FFFFFF; background-color: #850000">';
    $body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
    $body_message .= '<tr style="background: #850000;"><td><strong>From:</strong> </td><td>'.$name.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Email:</strong> </td><td>'.$email.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Phone:</strong> </td><td>'.$phone.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Address:</strong> </td><td>'.$address .'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>City:</strong> </td><td>'.$city.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>State:</strong> </td><td>'.$state.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Zipcode:</strong> </td><td>'.$zipcode .'</td></tr>';
    $body_message .= '</table>';
    $body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier1.'</td><td><strong>Quanity:</strong> </td><td>'.$qty1.'</td><td><strong>Part Number:</strong></td><td>'.$p_number1.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td> ' .$supplier2.'</td><td><strong>Quanity:</strong> </td><td>'.$qty2.'</td><td><strong>Part Number:</strong></td><td>'.$p_number2.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier3.'</td><td><strong>Quanity:</strong> </td><td>'.$qty3.'</td><td><strong>Part Number:</strong></td><td>'.$p_number3.'</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier4 .'</td><td><strong>Quanity:</strong> </td><td>'.$qty4.'</td><td><strong>Part Number:</strong></td><td>'.$p_number4.'</td></tr>';
    $body_message .= '</table>';
    $body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
    $body_message .= '<tr style="background: #850000;"><td colspan="3"><strong>Message:</td></tr>';
    $body_message .= '<tr style="background: #850000;"><td rowspan="3"colspan="3">' .$message .'</td></tr>';
    $body_message .= '</table>';
    $body_message .= '</body></html>'; 
    $headers = "From: " .$email . "r\n" ;
    $headers .= "Reply-To: ".$email . "\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";                   


    //put your email address here
    mail("email@yourdomain.com, $email", $subject, $body_message, $headers);
    ?>
    <!--Display a thankyou message in the callback -->
    <div id="mail_response">
    <h3>Thank you for your order&nbsp<?php echo $name ?>!</h3><br />
    <p>We will be calling to verify your order and take payment.</p><br />
    <p>Please look over your order above and call (281) 970-1200 if incorrect.</p><br />
    <h5>Message sent on: </h5>
    <p><?php echo $todayis ?></p>
    </div>   

0 个答案:

没有答案