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');
}
4

1 回答 1

3

使用此代码

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

您只需要使用isset方法并检查是否设置了天气。如果是,则将其文本显示在value.

于 2013-02-28T04:30:29.223 回答