0

我的 JQuery Post 脚本遇到了一些问题。我使用 Jquery 提交(弹出)表单,当我禁用此功能时,一切运行顺利。(我只是不想离开我的表单页面)。

我的表单输入的一部分(一些单选按钮)

<label><input type="radio" name="algemene_rating" id="algemene_rating" value="zeer_slecht" />1</label>
<label><input type="radio" name="algemene_rating" id="algemene_rating" value="slecht" />2</label>
<label><input type="radio" name="algemene_rating" id="algemene_rating" value="matig" />3</label>
<label><input type="radio" name="algemene_rating" id="algemene_rating" value="goed" />4</label>
<label><input type="radio" name="algemene_rating" id="algemene_rating" value="zeer_goed" />5</label>

我的表单输入的一部分(一些复选框)

<input type="checkbox" name="suggestie_dienstverlening" value="true" style="float:left; margin-bottom:5px;"/><div class="FeedbackCheckbox">Dienstverlening</div>
<input type="checkbox" name="suggestie_opmaak" value="true" style="float:left"/><div class="FeedbackCheckbox">Opmaak</div>
<input type="checkbox" name="suggestie_functionaliteit" value="true" style="float:left; margin-bottom:5px;"/><div class="FeedbackCheckbox">Functionaliteit</div>
<input type="checkbox" name="suggestie_site_inhoud" value="true" style="float:left; margin-bottom:5px"/><div class="FeedbackCheckbox">Site inhoud</div>
<input type="checkbox" name="suggestie_anders" value="true" style="float:left"/><div class="FeedbackCheckbox">Anders...</div>

我的表单输入的一部分(文本(区域))

<input type="text" name="url_van_foutpagina" style="font-size:9px; width:275px">
<input id="e-mail" type="text" value="" name="email" />

没有 JQuery,有了这个 PHP 脚本,一切都会顺利进行:

<?php

//collect vals
$algemene_rating = htmlspecialchars($_POST['algemene_rating']);
if ($_POST['suggestie_dienstverlening'] == "true")  {$sugestie_onderwerp .= "<li> Dienstverlening </li>";}
if ($_POST['suggestie_opmaak'] == "true")           {$sugestie_onderwerp .= "<li> Opmaak </li>";}
if ($_POST['suggestie_functionaliteit'] == "true")  {$sugestie_onderwerp .= "<li> Functionaliteit </li>";}
if ($_POST['suggestie_site_inhoud'] == "true")      {$sugestie_onderwerp .= "<li> Site inhoud </li>";}
if ($_POST['suggestie_anders'] == "true")           {$sugestie_onderwerp .= "<li> Anders.. </li>";}
$url_van_foutpagina = htmlspecialchars($_POST['url_van_foutpagina']);

//Collect 'Emailadres'
$email = htmlspecialchars($_POST['email']);

// Collect: 'Attributes'
$tijd = time();
$datum = strftime("%d/%m/%y %H:%M", $tijd);
$ip = getenv("REMOTE_ADDR");

// Collect 'Mail info'
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Het bericht voor de ontvanger 
$message = '<html><body>';
$message .= '<table rules="all" style="background-color:#F8F8F8; width:600px; font-family:arial; font-size:11px; valign:top">';
$message .= '<table rules="all" border="1px solid #666666" style="background-color:#F8F8F8; width:600px; font-family:arial; font-size:11px;">';
$message .= '<td style="width:200px;"  /></td>';
$message .= "<tr><td><strong></strong> </td><td><h3>Feedbackformulier Multihout.nl</h3></td></tr>";
// 'Attributes'
$message .=  "<tr><td><hr/></td><td><hr/></td></tr>";
$message .=  "<tr><td><strong>Feedback datum:</strong> </td><td>        " . $datum . "</td></tr>";
$message .=  "<tr><td><strong>Feedback e-mailadres:</strong> </td><td>  " . $email . "</td></tr>";
$message .=  "<tr><td><strong>Feedback IP-adres:</strong> </td><td>     " . $ip . "</td></tr>";
// 'Algemeen'
$message .=  "<tr><td><hr/></td><td><hr/></td></tr>";
$message .=  "<tr><td><strong>Algemene rating van de site:</strong> </td><td>" . $algemene_rating . "</td></tr>";
$message .=  "<tr><td><hr/></td><td><hr/></td></tr>";
$message .=  "<tr><td><strong>Feedback over URL:</strong> </td><td>" . $url_van_foutpagina . "</td></tr>";
$message .=  "<tr><td><hr/></td><td><hr/></td></tr>";
$message .=  "<tr><td><strong>Onderwerp suggestie:</strong> </td><td>" . $sugestie_onderwerp . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>"; 

// Gedeelte voor het verzenden van het bericht
$mailadres = "test@test.nl";
$message = str_replace ("<br>","\n", $message);
$headers .= "From: Test <test@test.nl>" . "\r\n";
mail("$mailadres", "Nieuw bericht via mailformulier", $message, $headers); 

?>
<!--Display a thankyou message in the callback -->
<div id="mail_response">
    <h3>Thank you <?php echo $name ?>!</h3><br />
    <p>I will answer your message soon as possible.</p><br /><br /><br />
    <h5>Message sent on: </h5>
    <p><?php echo $todayis ?></p>
</div>    

但是如果我使用这个 JS 脚本(提交/发布部分),我会在我的邮件、表格中得到未定义的值。

   //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.message.value == ""))
        {
            return false;
        } 

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

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

            //send the ajax request
            $.post('mail.php',{
                            algemene_rating:$('#algemene_rating').val(),
    url_van_foutpagina:$('#url_van_foutpagina').val(),
    sugestie_onderwerp:$('#sugestie_onderwerp').val(),
    email:$('#email').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")', 2000);

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

我认为问题出在这里:

//send the ajax request
                $.post('mail.php',{
algemene_rating:$('#algemene_rating').val(), url_van_foutpagina:$('#url_van_foutpagina').val(),
sugestie_onderwerp:$('#sugestie_onderwerp').val(), email:$('#email').val()},

但我不知道如何正确地在 jquery 中发布。或者以正确的方式将其检索到 .html 邮件中。我尝试对整个表单进行 .serialize,但我不知道如何将其“反序列化”,以便正确填写 html 邮件。

我希望你们能帮助我..现在期待并试图自己解决这个问题..:)

4

1 回答 1

0

我相信您正在寻找的是一个 ajax 请求。您想在不刷新页面的情况下发送数据。

http://api.jquery.com/jQuery.ajax/

于 2012-04-23T12:13:49.963 回答