2016-04-01 21 views
0

更新:電子メールフィールドの電子メールアドレスのチェックでは、電子メールアドレス新しいか、mySQLデータベースに存在します。私は電子メールがデータベースのユーザーテーブルの電子メールフィールドに存在する場合にのみエラーを返すようにしたいと思います。登録フォームを送信する前に重複する/既存の電子メールアドレスの電子メールフィールドを確認する方法

登録ページの現在のコードは次のとおりです。

サーバー側の応答がなければならないJSON文字列でなければなりません:

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
\t <script src="http://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.js"></script> 
 
\t <script src="http://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.min.js"></script> \t 
 
\t <script src="http://cdn.jsdelivr.net/jquery.validation/1.15.0/additional-methods.js"></script> \t 
 
\t <script src="http://cdn.jsdelivr.net/jquery.validation/1.15.0/additional-methods.min.js"></script> \t \t \t 
 
\t <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> \t 
 
\t <script type="text/javascript"> 
 
$().ready(function(){ \t \t 
 
\t $("#register").validate({ 
 
\t \t errorElement: 'span', 
 
\t \t errorPlacement: function (error, element) { 
 
\t \t  if (element.attr("type") == "checkbox") { 
 
\t \t   error.insertAfter($(".term")); 
 
\t \t  } else { 
 
\t \t \t \t error.insertAfter(element); 
 
\t \t  } 
 
\t \t }, 
 
\t \t rules: { 
 
\t \t  su_email \t \t : { 
 
\t \t \t \t required: true, 
 
\t \t \t \t email: true, 
 
\t \t \t \t remote: "/email_check.php" \t \t \t 
 
\t \t \t }, 
 
\t \t  su_password \t \t : { 
 
\t \t \t \t minlength: 6, 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_conpassword \t : { 
 
\t \t \t \t equalTo : "#su_password" 
 
\t \t \t }, 
 
\t \t  su_name \t \t \t : { 
 
\t \t \t \t minlength: 3, 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_phone \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_city \t \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_country \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_gender \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_quest \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_ans \t \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t }, 
 
\t \t  su_terms \t \t : { 
 
\t \t \t \t required: true 
 
\t \t \t } 
 
\t \t }, 
 
\t \t messages: { \t \t \t \t \t 
 
\t \t \t su_email: { 
 
\t \t \t \t required: "Please enter your email address", 
 
\t \t \t \t email: "Please enter a valid email address", 
 
\t \t \t \t remote: jQuery.validator.format("{0} is already in use") 
 
\t \t \t }, 
 
\t \t \t su_password: { 
 
\t \t \t \t required: "Provide a password", 
 
\t \t \t \t minlength: jQuery.validator.format("Enter at least {0} characters") 
 
\t \t \t }, 
 
\t \t \t \t su_conpassword: { 
 
\t \t \t \t equalTo: "Repeat your password" \t \t \t \t 
 
\t \t \t }, 
 
\t \t \t \t su_name: { 
 
\t \t \t \t required: "Enter your full name", 
 
\t \t \t \t minlength: jQuery.validator.format("Enter at least {0} characters") 
 
\t \t \t }, 
 
\t \t \t \t su_phone: { 
 
\t \t \t \t required: "Enter your phone number" 
 
\t \t \t }, 
 
\t \t \t \t su_city: { 
 
\t \t \t \t required: "Enter your city" \t \t \t \t \t \t 
 
\t \t \t }, 
 
\t \t \t \t su_country: { 
 
\t \t \t \t required: "Select your country" \t \t \t \t \t \t 
 
\t \t \t }, 
 
\t \t \t \t su_gender: { 
 
\t \t \t \t required: "Select your gender" \t \t \t \t \t \t 
 
\t \t \t }, 
 
\t \t \t \t su_quest: { 
 
\t \t \t \t required: "Select a security question" \t \t \t \t \t \t 
 
\t \t \t }, \t 
 
\t \t \t \t su_ans: { 
 
\t \t \t \t required: "Select a security answer" \t \t \t \t \t \t 
 
\t \t \t }, 
 
\t \t \t \t su_terms: { 
 
\t \t \t \t required: "You must agree to terms to join" \t \t \t \t \t \t 
 
\t \t \t } 
 
\t \t } 
 
\t }); 
 
\t \t 
 
\t $('.condition').click(function() { \t 
 
\t \t if ($(this).is(':checked')) { 
 
\t \t  $('#termscondition').dialog({ 
 
\t \t   modal: true, 
 
\t \t   width: 600, 
 
\t \t \t \t buttons: { 
 
\t \t \t \t \t Ok: function() { 
 
\t \t \t \t \t  $(this).dialog('close'); 
 
\t \t \t \t \t } \t \t    
 
\t \t \t \t } 
 
\t \t  }); 
 
\t \t } else { 
 
\t \t  $('#termscondition').dialog('close'); 
 
\t \t } 
 
\t }); 
 
}); 
 
</script>
<?php \t 
 
    \t include('includes/inc-public.php'); 
 
    \t include('includes/classes/class.user.php'); 
 
\t $user = new User(); 
 
\t $email = $_GET['su_email']; 
 
\t $valid = false; 
 
\t header('Content-Type: application/json'); \t 
 
\t 
 
\t if(!is_null($email)){ \t \t 
 
\t \t $is_valid = $user->get_email($email); 
 
\t \t if($is_valid){ 
 
    \t \t \t echo json_encode($is_valid); 
 
\t \t } 
 
    \t \t else{ 
 
\t \t \t echo json_encode($valid); \t \t \t \t \t 
 
\t \t } 
 
    \t }; 
 
?>

signup form when a new email address is being entered in the email field users table of mysql database

+0

これはサーバー側の言語では不可能です。クライアント側にはJavaScriptが必要です – Fabio

+0

jquery.validate.jsのjscriptを使用しています。 –

+0

これは既存のメールアドレスがメールフィールド[2]に入力されているときのスクリーンショットです:http://i.stack.imgur.com/Y1bTP.jpg –

答えて

0

documentationからのために "真"である有効な要素であり、デフォルトのエラーメッセージを使用して、無効な要素に対しては「偽」、未定義、またはnullにすることができます。サーバー側の応答が文字列の場合、たとえば。 "その名前は既に取られています、代わりにpeter123を試してください"、この文字列は、デフォルトの代わりにカスタムエラーメッセージとして表示されます。

したがって、is_validをtrueに変更する必要があります。

+0

に設定されている" \t \t \t} \t \t \t \t} \t \t \t \t $ this-> sql = "SELECT 'vemail' FROM 'wmldir_users' WHERE vemail = '"。$ email。"'"; \t \t \t \t \t \tの$ this - >データ=の$ this - > fetch_row_assoc(の$ this - > SQL)。 \t \t \t場合(!空(の$ this - >データ)) \t \t \t \t戻ります$ this->データ; \t \t \t else { \t \t \t \t return false; } \t \t \t \t} 「 \t \t \tは? –

+0

はい代わりの$ this - >を返すのデータは、検証が、私はそれかどうかを任意のメールアドレスを入力したときに、今、私は偽の取得私はこれをtrueに変更し – JahShaka

+0

を動作しません。そうでなければtrueを返します新しいか、mysqlデータベースに存在しています –

関連する問題