<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
$user_name = $email = $description = $gender = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["user_name"]))
{
$user_name = "";
}
else
{
$user_name = clean_data($_POST["user_name"]);
}
if (empty($_POST["email"]))
{
$email = "";
}
else
{
$email = clean_data($_POST["email"]);
}
if (empty($_POST["description"]))
{
$description = "";
}
else
{
$description = clean_data($_POST["description"]);
}
if (empty($_POST["gender"]))
{
$gender = "";
}
else
{
$gender = clean_data($_POST["gender"]);
}
}
function clean_data($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?><h2>Keep The Values in The Form With PHP</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
User Name: <input type="text" name="user_name" value="<?php echo $user_name;?>">
<br /><br />
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<br / ><br / >
Description: <textarea name="description" rows="5" cols="40">
<?php echo $description;?></textarea>
<br /><br />
Gender:
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>