I'm going a little nuts over this and was working on it practically all day yesterday. I'm creating a form for people to enter comments. There are 3 required fields, name, comment, and a question so bots don't post. If I fill out 2 of the three, the form says please fill out whatever is missing but it removes what was previously entered in the other 2 fields. I looked up sticky forms and I finally got it to stick when the form is submitted, but after all 3 fields are submitted, the information still stays. Is there any way to reset the form after all of the information has been submitted without having it reset to fill in the required fields?? if (isset($_POST['submit']) || isset($_POST['submit_x'])) { if($code != 4) { $badform = 1; } if (trim($nickname) == '') { $badform = 1; } if (trim($comment) == '') { $badform = 1; } if (!get_magic_quotes_gpc()) { $nickname = addslashes($_POST['nickname']); $comment = addslashes($_POST['comment']); $code = addslashes($_POST['code']); } if ($badform != 1) { $query = "this is the query"; /* Quotes are important in this lines statment */ $result = mysql_query($query) or die("sorry something went wrong"); } } <form action="<?php echo "blog.php?id=$id" ?>" method=post> <?php if(isset($_POST['submit']) || isset($_POST['submit_x'])) { if (trim($nickname) == '') { echo "<p class=\"error\">What do people call you?</p>"; } } ?> <input class="textinput" name="nickname" type="text" maxlength="12" value="<?php if (isset($_POST['nickname'])) echo $_POST['nickname']; ?>" /> <?php if(isset($_POST['submit']) || isset($_POST['submit_x'])) { if (trim($comment) == '') { echo "<p class=\"error\">At least say something!</p>"; } } ?> <textarea class="texta" rows="5" name="comment"><?php if (isset($_POST['comment'])) echo $_POST['comment']; ?></textarea> <?php if(isset($_POST['submit']) || isset($_POST['submit_x'])) { if ($code != 4) { echo "<p class=\"error\">Not everyone can figure this out...think about it.</p>"; } } ?> <input class="textinput" name="code" type="text" maxlength="1" /> <input type="hidden" name="blogid" value="<?php echo "$id" ?>" /> <input src="/images/addComment.gif" type="image" name="submit" value="Add Comment" alt="Add Comment" /> </form> PHP:
After all 3 are submitted and verified I would probably show a different page. However you could just do $_POST = ""; to wipe the post variables.
Wow, obviously you can tell im a n00b at this php stuff. I went crazy yesterday and all I had to do was freakin add that one little line to clear the post variable. Do you know all the crazy crap I was reading on all these damn sites and not one mentioned anything like that!!! Anyway, thank you very much, i really really appreciate it, I'm gonna add a green rep to your name cuz out of all the people who read this post, your the only one who answered.
Just to let you know, I really recommend that you use mysql_real_escape_string() in place of addslashes()