开发者

PHP sticky form question

I'm using a PHP sticky form and was wondering is ther开发者_StackOverflow中文版e a way I can clear a forms fields once its been submitted by the user?

A sticky form is simply a standard HTML form that remembers how you filled it out. This is a particularly nice feature for end users, especially if you are requiring them to resubmit a form (for instance, after filling it out incorrectly in the first place).


You could have some default values and update the fields to the values using Javascript , in case you do not want to reload the page. If you do want to reload the page, and use PHP sticky form, populate the form after clearing out the GET values.


If you want it to clear the data, you can do this:

<html>
<head>
<title>A Self-Clearing Form</title>
<script>
function clearForms()
{
  var i;
  for (i = 0; (i < document.forms.length); i++) {
    document.forms[i].reset();
  }
}
</script>
</head>
<body onLoad="clearForms()" onUnload="clearForms()">
<h1>A Self-Clearing Form</h1>
<form method="post" action="page2.php" name="test">
<input name="field1"/> Field One
<p>
<input name="field2" type="radio" value="One"/>One
<input name="field2" type="radio" value="Two"/>Two

<input name="field2" type="radio" value="Three"/>Three
<input name="field2" type="radio" value="Four"/>Four
<p>
<input type="submit" value="Submit Form Data"/>
</form>
</body>
</html>

This will clear the form when the HTML body loads completely.


It depends on your implementation, but the solution probably involves clearing the session variables that are used to hold the form data. If you're using a cut and paste solution I would suggest reading the documentation further or maybe looking over the code in detail to see how everything is stored.

If you want to check the session variables to see if the form data is in there you can use:

echo '<pre>';
print_r($_SESSION);
echo '</pre>';
die; // this line is optional
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜