0

How can I display the name the user entered back into the form if the user forgot to enter a password? i.e. echo $submitted_user into value="" under Username.

if(empty($_POST['password'])) {
    $submitted_user = htmlentities($_POST['username']);
    echo '<form action="register.php" method="post">
    Username:<br />
    <input type="text" name="username" value="" autofocus="autofocus" />
    <br /><br />
    Password:<br />
    <input type="password" name="password" value="" />
    <br /><br />
    <input type="submit" value="Register" />
    </form>';

    exit();
}
4

1 回答 1

2

Append the $submitted_user to value should do it.

if(empty($_POST['password'])) {
    $submitted_user = htmlentities($_POST['username']);
    echo '<form action="register.php" method="post">
    Username:<br />
    <input type="text" name="username" value="'.$submitted_user.'" autofocus="autofocus" />
    <br /><br />
    Password:<br />
    <input type="password" name="password" value="" />
    <br /><br />
    <input type="submit" value="Register" />
    </form>';

    exit();
}
于 2013-04-10T03:12:02.110 回答