Re: Making the Contents of a PHP Page Persist

by David Mintz <mambomintz(at)yahoo.com>

 Date:  Thu, 14 Dec 2000 19:55:22 -0800 (PST)
 To:  Rudy Gomez <rudy(at)cyberangler.com>,
hwg-languages(at)hwg.org
  todo: View Thread, Original

--- Rudy Gomez <rudy(at)cyberangler.com> wrote:
> > Doug wrote:
> > How do I get the contents of my form to persist
> after I click the Submit
> > button?  I'm hoping to use JavaScript to do
> this...
> 

Doing it with Javascript when PHP is there seems kind
of a lot of work.

If what you mean is making the form state persist
across invocations, Perl/CGI.pm style, e.g., when the
user enters something invalid and you want to print an
error message and re-present the form in the same
state as when it was submitted... then this sort of
thing works for me:
===================================
<!-- html here -->
<? if ($HTTP_POST_VARS) {
    if ($favorite_beer != "Guinness") {
        print "Sorry, that's wrong. Please try again";
    } else {
        print "Excellent choice!";
        print "</body></html>";
        exit;
    }
}
?>
<form action="<? print $PHP_SELF; ?>" method="post">
What kind of beer do you like?
<input type="text" name="favorite_beer" value="<?
print $favorite_beer ?>">
</form></body></html>

===================================

You might need to call htmlspecialchars() and perhaps
stripslashes()(depending on how your PHP is
configured) on $favorite_beer to account for whatever
the user might put in there. But this approach seems
to work for me.

BTW I find it kind of cool, coming from the discipline
of Perl and using the  -w switch and the 'strict'
pragma, to see how this works because PHP just doesn't
seem to care whether $favorite_beer has been declared
or initialized.

David Mintz
Spanish Interpreter, US District Court
Southern District of New York
Web Design & Hosting http://dmintzweb.com/
Personal http://panix.com/~dmintz/

=====
David Mintz
        http://www.panix.com/~dmintz

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA