2013-02-28 73 views
1

我有一個登錄表單,當我嘗試登錄並失敗時,我被髮送回登錄表單並且它是空白的。我想在失敗的嘗試中保留用戶名/電子郵件地址字段,以便我只需要再次鍵入密碼。關於我需要做什麼的建議?登錄嘗試失敗後保留字段

HTML:

  <?php if ($_GET['msg'] == 'failed') : ?> 
     <p style="color:red; font-weight: bold">Incorrect email or password. Try again!</p> 
     <?php endif; ?> 
     <form action="index.php?cmd=login" method="post" id="form"> 
      <div class="signup-form"> 
       <p> 
        <label>Email</label> 
        <input type="text" name="email" value="" class="textbox required email" /> 
       </p> 
       <p> 
        <label>Password</label> 
        <input type="password" name="password" value="" class="textbox required"/> 
       </p> 
       <p> 
        <label></label> 
        <input type="checkbox" name="rememberme" value="1" class="" checked="checked" /> Remember Me? 
       </p> 
       <p> 
        <a style="margin: 10px 0 0 0; color:#000;" class="button" href="javascript://" onclick="$('#form').submit()">Continue</a> <img src="images/ajax-loader.gif" class="loading" style="display: none;" /> 

和:

if ($_POST) { 
$login = $_USER->do_log_in(input($_POST['email']), md5($_POST['password']), $_POST['rememberme']); 
if ($login == true) { 
    $_SESSION['userid'] = $_USER->get_user_id(); 
    header('location: index.php'); 
}else 
    header('location: index.php?cmd=login&msg=failed'); 
} 

回答

3

使用此代碼

<input type="text" name="email" value="<?php if(isset($_POST['email'])) { echo $_POST['email']; } ?>" class="textbox required email" /> 

你只需要使用isset方法,並檢查天氣將其設置與否。如果是,則顯示value中的文字。

+0

我將POST數據傳遞給另一個頁面,然後標題重定向將其發送回表單頁面,標題重定向清除POST數據。這樣做安全嗎? 'header('location:index.php?cmd = login&msg = failed&email ='。$ _ POST ['email']);' – techora 2013-02-28 05:12:10

+0

做登錄完成時的頭重定向不會重定向它們。 – 2013-02-28 05:15:18

+1

良好的通話,非常感謝您的幫助。 – techora 2013-02-28 05:21:53