2011-07-23 9 views
1

にフォームを隠す:http://www.bgv.co.za/testspace/contact_3.phpjQueryの - 私は成功した提出の私のフォームを非表示にしたい提出

その組み合わせPHP jQueryの雑種:ここ

はtestspaceへのリンクです。現時点では、jQueryバリデーターを使用しています。必要なフィールドを表示する方法として、divをラップする入力フィールドのクラスを変更するカスタムスクリプトを追加しました。ここで

は、私はPHP

<?php 

$件名= "ウェブサイトのお問い合わせフォームお問い合わせ" に持っているものです。

//(ISSET($ _ POST [ '提出'])){

//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; 

} 

} >

、ここでスクリプト領域であれば、フォームが を提出している場合:?は

$(document).ready(function(){ 
$('#contactform').validate({ 
     showErrors: function(errorMap, errorList) { 

      //restore the normal look 
      $('#contactform div._required').removeClass('_required').addClass('xrequired'); 

      //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('xrequired').addClass('_required'); 
     } 

}); });

だから、誰かがあなただけの連絡先フォームの下に新しい見出しを参照してください有効なフォームを送信した瞬間に - そのここから:

 <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> 
    <h1 class="success_form">Thank You!</h1> 
    <?php } ?> 

、以下それがフォームに入力されたデータです。

しかし、私は非表示にしたいこと下記のフォームshoing ....ここ:)

を助けてください、私が追加された新しいビットであるFlashbackzoo

 $("#content").empty(); 
    $("#content").append(
    "<p>If you want to be kept in the loop...</p>" + 
    "<p>Or you can contact...</p>" 
    ); 
    $('h1.success_').removeClass('success_').addClass('success_form'); 
    $('#contactform').hide(); 

}, 

答えて

2

のおかげで提出するハンドラを追加します。..で。

$('#contactform').validate({ 
    showErrors: function(errorMap, errorList) { 
     // your code... 
    }, 
    submitHandler: function() { 
     $('#contactform').hide(); 
    } 
}); 

UPDATE

あなたのコメントBrettへの応答。あなたはsubmitHandlerを次のようなものに変更することができます。

submitHandler: function() { 
    $("#content").empty(); 
    $("#content").append(
     "<p>If you want to be kept in the loop...</p>" + 
     "<p>Or you can contact...</p>" 
    ); 
} 

これは、.empty()メソッドを使用してすべての子要素を#contentから削除します。その後、.append()メソッドを使用して#contentに要素を追加します。あなたはあなたが好きなセレクターの#contentを交換することができます。

+0

うんその仕事仲間:)その – brett

+0

一つのカントー、それはこれが...それはまた、フォームが – brett

+0

を結果隠しフォームを非表示にしないときあなたは、もはやインクルードはあなたのページに感謝見ないために乾杯。あなたがこのプロセスをここをクリックすれば> http://bgv.co.za/testspace/contact_2.php – brett

関連する問題