Hi guys,
I'm trying to make a register form. I have the following scripts:
functions.php (where I store the functions)
this is a part of it:
function valid_username($username, $minlength = 3, $maxlength = 30)
{
$username = trim($username);
if (empty($username))
{
echo "fill in a username";
}
if (strlen($username) > $maxlength)
{
echo "username to long";
}
if (strlen($username) < $minlength)
{
echo "username to short";
}
$result = ereg("^[A-Za-z0-9_\-]+$", $username); //only A-Z, a-z and 0-9 are allowed
if ($result)
{
return true; // ok no invalid chars
} else
{
echo "not-allowed charaters in username";
}
return false;
}
Register.php:
if (isset($_POST['register'])){
if (registerNewUser($_POST['username'], $_POST['password'], $_POST['password2'], $_POST['email'])){
echo "Thank you for registration <br/>
";
}else {
show_registration_form();
}
} else {
// has not pressed the register button
show_registration_form();
}
Registration form
'<form action="./register.php" method="post">
<h2>Register</h2>
<dl>
<dt><label for="username">user</label></dt>
<dd><input name="username" type="text" id="username" maxlength="30">
</dd>
</dl>
<dl>
<dt><label for="password">password (minstens 4 symbolen, maximum 15)</label></dt>
<dd><input name="password" type="password" id="password" maxlength="15">
</dd>
</dl>
<dl>
<dt><label for="password2">retype password</label></dt>
<dd><input name="password2" type="password" id="password2" maxlength="15">
</dd>
</dl>
<dl>
<dt><label for="email">Email</label></dt>
<dd><input name="email" type="text" id="email" maxlength="255">
</dd>
</dl>
<p>
<input name="reset" type="reset" value="reset">
<input name="register" type="submit" value="Register">
</p>
</form>';
Now, if somebody fills in a username thats to short, or an invalid password,
the warnings are displayed in the top of the form.
But I would like to have it displayed next to the fill-in boxes
For example:
Username : [ !(§"'(è'§!"è§' ] Invalid username
But how do I have to do this?
Thank you!