I have entered my code below I am trying to make my form save users information if they for get another field so when they are told to submit something they missed they do not loose the data they already entered (example: they fill in everything except user name and when they click send all the other fields will still show what they have already typed) This seems to be working fine by using value="\"".$_POST['fieldname']. When I test this though it is not saving the comments field is there a different code I do not know about or is it a placement issue any help would be most appreciated.
Code:
<?php function printForm($strMessage){ echo "<strong>" .$strMessage."</strong>"; echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF']. "\" name=\"form\">\n<br>"; echo "Your Name: <input type=\"text\" Name=\"yname\" value=\"" .trim($_POST['yname'])."\"><br>"; echo "Your Email: <input type=\"text\" Name=\"yemail\" value=\"" .trim($_POST['yemail'])."\"><br>"; echo "Username: <input type=\"text\" Name=\"yusername\" value=\"" .trim($_POST['yusername'])."\"><br>"; echo "Password: <input type=\"password\" Name=\"pword\" value=\"" .trim($_POST['pword'])."\"><br>"; echo "Confirm Password: <input type=\"password\" Name=\"cpword\" value=\"" .trim($_POST['cpword'])."\"><br>"; echo "Comments: <textarea name=\"comments\" rows=\"5\" cols=\"20\" value=\"" .trim($_POST['comments'])."\"></textarea><br>"; echo "<input type=\"submit\" value=\"send\" Name=\"submit\"/>\n<br>"; echo "</form>\n"; } ?> <html> <head> <title>Self Submitting Sticky Form</title> <style>body { background-color:red; } </style> </head> <body> <?php if(isset($_POST['submit'])){ $yourname=trim($_POST['yname']); $youremail=trim($_POST['yemail']); $yourusername=trim($_POST['yusername']); $yourpassword=trim($_POST['pword']); $yourcpassword=trim($_POST['cpword']); if ($yourname==''){ $strMessage='Please enter your name.'; printForm($strMessage); } elseif ($youremail==''){ $strMessage='Please enter your email.'; printForm($strMessage); } elseif ($yourusername==''){ $strMessage='Please enter your username.'; printForm($strMessage); } elseif ($yourpassword==''){ $strMessage='Please enter your password.'; printForm($strMessage); } elseif ($yourcpassword==''){ $strMessage='Please confirm your password.'; printForm($strMessage); } elseif ($yourcpassword != $yourpassword){ $strMessage='passwords must match.'; printForm($strMessage); } elseif(strlen($yourpassword) <= 3 ){ $strMessage='passwords must be at least 4 characters.'; printForm($strMessage); } else{ $strMessage='Thank you. your information was sent.'; echo $strMessage; } } else{ $strMessage='Please enter all fields below:'; printForm($strMessage); } ?> </body> </html>
Also I am sorry for my code showing up like this I tried to wrap it in the code tags and this is how it displayed I am also going to copy and paste below with out the code tags becuase I think I used them wrong.
<?php
function printForm($strMessage){
echo "<strong>" .$strMessage."</strong>";
echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF']. "\" name=\"form\">\n<br>";
echo "Your Name: <input type=\"text\" Name=\"yname\" value=\"" .trim($_POST['yname'])."\"><br>";
echo "Your Email: <input type=\"text\" Name=\"yemail\" value=\"" .trim($_POST['yemail'])."\"><br>";
echo "Username: <input type=\"text\" Name=\"yusername\" value=\"" .trim($_POST['yusername'])."\"><br>";
echo "Password: <input type=\"password\" Name=\"pword\" value=\"" .trim($_POST['pword'])."\"><br>";
echo "Confirm Password: <input type=\"password\" Name=\"cpword\" value=\"" .trim($_POST['cpword'])."\"><br>";
echo "Comments: <textarea name=\"comments\" rows=\"5\" cols=\"20\" value=\"" .trim($_POST['comments'])."\"></textarea><br>";
echo "<input type=\"submit\" value=\"send\" Name=\"submit\"/>\n<br>";
echo "</form>\n";
}
?>
<html>
<head>
<title>Self Submitting Sticky Form</title>
<style>body {
background-color:red;
}
</style>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$yourname=trim($_POST['yname']);
$youremail=trim($_POST['yemail']);
$yourusername=trim($_POST['yusername']);
$yourpassword=trim($_POST['pword']);
$yourcpassword=trim($_POST['cpword']);
if ($yourname==''){
$strMessage='Please enter your name.';
printForm($strMessage);
}
elseif ($youremail==''){
$strMessage='Please enter your email.';
printForm($strMessage);
}
elseif ($yourusername==''){
$strMessage='Please enter your username.';
printForm($strMessage);
}
elseif ($yourpassword==''){
$strMessage='Please enter your password.';
printForm($strMessage);
}
elseif ($yourcpassword==''){
$strMessage='Please confirm your password.';
printForm($strMessage);
}
elseif ($yourcpassword != $yourpassword){
$strMessage='passwords must match.';
printForm($strMessage);
}
elseif(strlen($yourpassword) <= 3 ){
$strMessage='passwords must be at least 4 characters.';
printForm($strMessage);
}
else{
$strMessage='Thank you. your information was sent.';
echo $strMessage;
}
}
else{
$strMessage='Please enter all fields below:';
printForm($strMessage);
}
?>
</body>
</html>