2017-12-29 17 views
1

私のコードに大きな問題があります。登録では、私は私のpassowrdを比較し、彼は一致しないパスワードを表示します。これはコードパスワード比較

{!! Form::open(array('url' => 'auth/postregister', 'class' => 'horizontal-form', 'id' => 'formRegister', 'method' => 'POST')) !!} 
    {{ csrf_field() }} 
       <label>Email</label> 
       {!! Form::text('u_email', null, array('placeholder' => '[email protected]', 'class' => 'form-group', 'id' => 'u_email', 'required')) !!} 
       <label>Mot de passe</label> 
       {!! Form::password('pwd1', null, array('placeholder' => '********', 'class' => 'form-group', 'id' => 'pwd1', 'required')) !!} 

       <label>Confirmer votre mot de passe</label> 
       {!! Form::password('pwd2', null, array('placeholder' => '********', 'class' => 'form-group', 'id' => 'pwd2', 'required')) !!} 
       <p id="message"></p> 

       <button type="submit" id="subscribe" class="btn btn-danger">S'enregistrer</button> 
{!! Form::close() !!} 
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js"></script> 
<script> 
$("#formRegister").validate({ 
    rules: { 
    pwd1: "required", 
    pwd2: { 
     equalTo: "#pwd1" 
    } 
    } 
}); 
</script> 

パスワードは入力が赤であり、投稿データが通過しないことを確認します。 はあなたのアイデア

+0

「私は私のpassowrdを比較して、彼はパスワードを表示する」それが何を意味するのでしょうか? – lagbox

+0

私はこれがhttps://laravel.com/docs/5.5/validation#rule-sameを探していると思います。だから 'pwd2:same:pwd1'を使用してください – Rik

+0

@lagbox私は2つのフィールドのパスワードを比較し、ビュー"パスワードが一致しません " –

答えて

0

をお持ちのあなたは、このようなあなたのルールを追加するには、jQueryのバリデータを拡張することができます

<script> 

    jQuery.validator.addMethod('passwordMatch', function(value, element) { 

     // The two password inputs 
     var password = $("#pwd1").val(); 
     var confirmPassword = $("#pwd2").val(); 

     // Check for equality with the password inputs 
     if (password != confirmPassword) { 
      return false; 
     } else { 
      return true; 
     } 

    }, "Your Passwords Must Match"); 

    $("#formRegister").validate({ 
     rules: { 
      pwd1: { 
       required: true, 
       minlength: 5 
      }, 
      pwd2: { 
       required: true, 
       minlength: 5, 
       passwordMatch: true // the added rule 
      } 
     }, 

     // If you want some custome messages :) 
     messages: { 
      pwd1: { 
       required: "What is your password?", 
       minlength: "Your password must contain more than 5 characters" 
      }, 
      pwd2: { 
       required: "You must confirm your password", 
       minlength: "Your password must contain more than 5 characters", 
       passwordMatch: "Your Passwords Must Match" // custom message for mismatched passwords 
      } 
     } 
    }); 
</script> 

シモンズ:source

+0

問題はjavascriptではありません。私はタイプテキストでパスワードを変更しました。これは同じパスワードですが、入力タイプのパスワードでも同じ問題です。あなたは考えましたか? –

+0

更新された答えを確認してください! – Maraboc

+0

それはあなたのために働いていますか? – Maraboc

関連する問題