Hi, I'm using some validation on the server side so that if one of the fields is empty it will come back with an error, and some other things.
When I do this it clears the form, which is really annoying as you have to type things out again. I'll just give you some of the code:
Just some simple validation, then the HTML:PHP Code:if (empty($_POST['username']) || empty($_POST['password']))
{
$error = "install.php?error=null";
redirect_to($error);
}
elseif (strlen($_POST['username']) <= 5)
{
$error = "install.php?error=ulength";
redirect_to($error);
}
elseif (strlen($_POST['password']) <= 5)
{
$error = "install.php?error=plength";
redirect_to($error);
}
The only was so far I've though of is to have the username come back in the form of a $_GET variable, and then just echo the value in the input box. Is there any other way to do this?Code:<form action="processinstall.php" method="post"> <label for="username">Username:</label> <input type="text" name="username"/><br /> <label for="password">Password:</label> <input type="password" name="password"/><br /> <input type="submit" name="submit" value="Login"/> </form> <?php if(isset($_GET['error'])) { echo ($_GET['error'] == "plength") ? "Password must contain at least 6 characters." : ""; echo ($_GET['error'] == "ulength") ? "Username must contain at least 6 characters." : ""; echo ($_GET['error'] == "null") ? "Please enter a username and password." : ""; } ?>
Of course I wouldn't do that with the password as that would be very unsecure. So is the $_GET method the best way, or not?



Reply With Quote

Bookmarks