2015-06-06 39 views
1

彈出後,我想在出現驗證錯誤時彈出Bootstrap模式,並將其顯示在模態上。 Php驗證在頁面重新加載後發生,所以如果發生錯誤,bootstrap模式應該彈出相應的錯誤。Bootstrap Modal在驗證通過Php

這是模態的代碼。

<div class="modal-dialog"> 

     <!-- Modal content--> 
     <div class="modal-content" > 
     <div class="modal-header" style="padding:35px 50px;"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
      <h3><span class="glyphicon glyphicon-lock"></span> Login</h3> 
     </div> 
     <div class="modal-body" style="padding:40px 50px;"> 
      <form role="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 

      <div class="form-group"> 
       <label for="usrname"><span class="glyphicon glyphicon-user"></span> Username</label> 
       <input type="text" class="form-control" id="u_email" name="u_email" value="<?php echo $u_email;?>" placeholder="Enter email"> 
       <span class="error"> <?php echo $u_emailErr;?></span> 
      </div> 
      <div class="form-group"> 
       <label for="psw"><span class="glyphicon glyphicon-eye-open"></span> Password</label> 
       <input type="text" class="form-control" id="password" name="password" value="<?php echo $password;?>" placeholder="Enter password"> 
       <span class="error"> <?php echo $passwordErr; echo $count;?></span> 
      </div> 
      <div class="checkbox"> 
       <label><input type="checkbox" value="" checked>Remember me</label> 
      </div> 
       <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-off"></span> Login</button> 
     </form> 
     </div> 
     <div class="modal-footer"> 
      <button type="submit" class="btn btn-danger btn-default pull-left" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button> 
      <p>Not a member? <a href="#" data-dismiss="modal" data-toggle="modal" data-target="#myModal1" data-backdrop="static" >Sign Up</a></p> 
      <p>Forgot <a href="#">Password?</a></p> 
     </div> 
     </div> 



    </div> 
    </div> 

這是PHP的驗證。

<?php 
// define variables and set to empty values 
$u_emailErr = $passwordErr = ""; 
$u_email = $password = ""; 
$count = 0; 

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{ 
    if (empty($_POST["u_email"])) 
    { 
    $u_emailErr = "Email is required"; 
    $count++; 
    } 
    else 
    { 
    $u_emailErr = test_input($_POST["u_email"]); 
    // check if e-mail address is well-formed 
    if (!filter_var($u_email, FILTER_VALIDATE_EMAIL)) 
    { 
     $u_emailErr = "Invalid email format"; 
     $count++; 
    } 
    } 

    if (empty($_POST["password"])) 
    { 
    $passwordErr = "Password is required"; 
    $count++; 
    } 
    else 
    { 
    $passwordErr = test_input($_POST["u_email"]); 

    } 
} 

function test_input($data) { 
    $data = trim($data); 
    $data = stripslashes($data); 
    $data = htmlspecialchars($data); 
    return $data; 
} 
?> 

任何人都可以幫忙...........?

+0

你想表現出直接的PHP腳本彈出?你使用ajax/jquery嗎? –

+0

驗證後,它必須顯示引導模態。釹現在使用簡單的HTML鏈接打開模式.........也沒有ajax/jquery – user3662663

+0

可能重複[Toggle Bootstrap modal with php trigger](http://stackoverflow.com/questions/19177691/toggle-引導模態與 - PHP-觸發) –

回答

0

必須添加以下代碼無效狀態