2011-07-25 30 views
0

私はこのようなことを理解しようとしていますので、専門家の助けと助言をいただければ幸いです。私はフォームを持っています - jQueryとAjaxを使用していますが、現時点では何がうまくいけないのか分かりません - データ入力をエコーバックすると(1つのフィールドのみ - コードを追加する方法はまだ分かります)私の電子メールに。他のPHP検証スクリプトにリンクする必要がありますか、それともすべてが1か所にあるのでしょうか? PHP www.bgv.co.za/testspace/contactos.phpここ送信する/電子メールを送信するフォームを取得

されています:ここで

は、試験空間へのリンクです(私の構文は、おそらくオフ) - 検証とAJAXのその組み合わせもの - ファイルが呼び出されます。

:ここpost.php

<?php 

$subject = "Website Contact Form Enquiry"; 

//If the form is submitted 
if(isset($_POST['submit'])) { 

//Check to make sure that the name field is not empty 
if(trim($_POST['contactname']) == '') { 
    $hasError = true; 
} else { 
    $name = trim($_POST['contactname']); 
} 

//Check to make sure sure that a valid email address is submitted 
if(trim($_POST['email']) == '') { 
    $hasError = true; 
} else if (!eregi("^[A-Z0-9._%-][email protected][A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { 
    $hasError = true; 
} else { 
    $email = trim($_POST['email']); 
} 

//Check to make sure comments were entered 
if(trim($_POST['message']) == '') { 
    $hasError = true; 
} else { 
    if(function_exists('stripslashes')) { 
     $comments = stripslashes(trim($_POST['message'])); 
    } else { 
     $comments = trim($_POST['message']); 
    } 
} 

//If there is no error, send the email 
if(!isset($hasError)) { 
    $emailTo = '[email protected]'; //Put your own email address here 
    $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments"; 
    $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; 

    mail($emailTo, $subject, $body, $headers); 
    $emailSent = true; 

} 

}

sleep(3); 


if (empty($_POST['email'])) { 
    $return['error'] = true; 
    $return['msg'] = 'You did not enter you email.'; 
} 
else { 
    $return['error'] = false; 
    $return['msg'] = 'You\'ve entered: ' . $_POST['email'] . '.'; 
} 

echo json_encode($return); 


?> 

は、JSファイル(ajaxSubmit呼び出されます)です

$(document).ready(function(){ 
$('#submit').click(function() { 

    $('#waiting').show(500); 
    $('#contactform').hide(0); 
    $('#message').hide(0); 

    $.ajax({ 
     type : 'POST', 
     url : 'post.php', 
     dataType : 'json', 
     data: { 
      email : $('#email').val() 
     }, 
     success : function(data){ 
      $('#waiting').hide(500); 
      $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success') 
       .text(data.msg).show(500); 
      if (data.error === true) 
       $('#contactform').show(500); 
     }, 
     error : function(XMLHttpRequest, textStatus, errorThrown) { 
      $('#waiting').hide(500); 
      $('#message').removeClass().addClass('error') 
       .text('There was an error.').show(500); 
      $('#contactform').show(500); 
     } 
    }); 

    return false; 
}); 
}); 

、ここでHTMLのDOCである:

<?php 
/** 
* @author Brett Vorster <www.kreatif.co.za> 
*/ 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="description" content="Orchard Systems 2012 Symposium Register Here" /> 
<meta name="keywords" content="Orchard Systems, Fruit Growers" /> 
<title>Orchard Systems 2012 | Contact Form</title> 

<link rel="stylesheet" type="text/css" media="all" href="css/style.css" /> 
<!--[if IE 7]> 
<link rel="stylesheet" type="text/css" media="all" href="css/styleie7.css" /> 
<![endif]--> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
<script src="jquery.validate.pack.js" type="text/javascript"></script> 

<script type="text/javascript"> 
$(document).ready(function(){ 

$('#contactform').validate({ 

showErrors: function(errorMap, errorList) { 
    //restore the normal look 
    $('#contactform div.xrequired').removeClass('xrequired').addClass('_required'); 
    //stop if everything is ok 
    if (errorList.length == 0) return; 
    //Iterate over the errors 
    for(var i = 0;i < errorList.length; i++) 
    $(errorList[i].element).parent().removeClass('_required').addClass('xrequired'); 
}, 

submitHandler: function(form) {    
    $('h1.success_').removeClass('success_').addClass('success_form'); 
    $("#content").empty(); 
    $("#content").append("<div id='sadhu'>This is just plain text. I need me a variable of somethink</div>"); 
    $('#contactform').hide(); 
    var usr = document.getElementById('contactname').value; 
    var eml = document.getElementById('email').value; 
    var msg = document.getElementById('message').value; 
    document.getElementById('out').innerHTML = usr + " " + eml + msg; 
    document.getElementById('out').style.display = "block"; 
    form.submit(); 
} 

}); 
}); 
</script> 



<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"> 
</head> 

<body class="contact"> 

<div id="container"> 
    <div class="sidebar"> 
     <img src="images/orchardsystems2012.png" title="Orchard Systems 2012 Logo" /> 
     <div class="data"><p> 
     10th International<br/>Symposium on<br/>Orchard Systems</p></div> 
     <div class="location"><p> 
     Stellenbosch<br/>South Africa<br/><span>3 - 6 December</span><br/>2012</p> 
     </div><a><img class="button" src="images/button_interested.png" title="I am interested - keep me informed" /></a> 
    <a href="registration.html" title="Click here to register"><img class="button" src="images/button_attend.png" title="I want to attend - registration form" /></a> 
    <a href="abstract.html" title="Click here to submit an abstract" ><img class="button" src="images/button_abstract.png" title="I want to take part - submit an abstract" /></a> 
     <img src="images/ishslogo.gif" style="margin:45px 63px 0px 63px;" /> 
    </div> 

    <div id="intainer"> 

     <div id="menu"> 
      <ul> 
       <li><a href="index.html" tabindex="i" title="Orchard Systems 2012 | Home" >Home</a></li> 
       <li><a href="aboutus.html" tabindex="au" title="About Us" >About Us</a></li> 
       <li><a href="programme.html" tabindex="p" title="Programme" >Programme</a></li> 
       <li><a href="registration.html" tabindex="r" title="Registration Form" >Registration</a></li> 
       <li><a href="venue.html" tabindex="v" title="Venue" >Venue</a></li> 
       <li><a href="accommodation.html" tabindex="a" title="Accommodation" >Accommodation</a></li> 
       <li><a href="tours.html" tabindex="t" title="Tours">Tours</a></li> 
       <li class="current"><a href="contact.html" tabindex="c" title="Contact Form">Contact</a></li> 
      </ul> 
     </div> 

     <div class="header"> 
     <h3 class="pagetitle">Contact</h3>  
     </div> 

     <div id="content"> 
     <p class="general_site">If you want to be kept in the loop please send us your details and we will update you. Suggestions for workshops are welcome.</p> 

<div id="message" style="display: none;"> 
      </div> 
      <div id="waiting" style="display: none;"> 
       Please wait<br /> 
      <img src="images/ajax-loader.gif" title="Loader" alt="Loader" /> 
      </div> 
      <form action="" id="contactform" method="post"> 
       <fieldset> 
        <legend>Demo form</legend> 
         <div class="_required"><label for="name">Name*</label><input type="text" size="50" name="contactname" id="contactname" value="" class="required" /></div><br/><br/> 
         <div class="_required"><label for="email">E-mail address*</label><input type="text" size="50" name="email" id="email" value="" class="required email" /></div><br/><br/> 
         <label for="message">Message</label><textarea rows="5" cols="50" name="message" id="message" class="required"></textarea><br/> 
         <div class="checko"><input type="checkbox" class="check" name="ISHS Member"/><label class="right" for="message">I am interested in a pre-symposium tour</label></div> 
         <input type="submit" value="submit" name="submit" id="submit" /> 
       </fieldset> 
      </form> 

     <p class="general_site">Or you can contact Retha Venter on +27 82 6567088 or [email protected]</p>    
     </div> 

    </div> 


</div> 
<div id="footer"> 
    <div class="footer_content"> 
     <div class="copyright"><a href="http://www.kreatif.co.za" target="_blank" title="website designed and developed by Kreatif Code.Design">© Orchard Systems 2012<br/> 
Designed by kreatif.co.za</a></div> 
    <span class="contactno">Tel +27 21 000 0000</span> 
    <span class="emailus"><a href="mailto:[email protected]?subject=Email enquiry from the website" title="Click here to email us">[email protected]</a></span> 
    </div> 
</div> 
<script type="text/javascript" src="js/ajaxSubmit.js"></script> 
</body> 
</html> 

私を助けてください、私はこれを行う方法を見つけようとして週末を費やしてきました。たぶん私はどこかにいるような気がして、それは何にもなりません。私はプログラマーではありません。私はこのすべての仕組みを理解していませんが、学習しています。

$subject = "Website Contact Form Enquiry"; 
$return['error'] = false; 
$name = trim($_POST['name']); 
$email = trim($_POST['email']); 
$comments = trim($_POST['message']); 

は、私はこのようなものがどのように機能するかを学んでいるように見えますねえ>

//If there is no error, send the email 
if(!isset($hasError)) { 
    $emailTo = '[email protected]'; //Put your own email address here 
    $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments"; 
    $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; 

    mail($emailTo, $subject, $body, $headers); 
    $emailSent = true; 

} 

と、この>あなたのPHPファイルにこれを追加することでソート

答えて

0

ありがとうございました!