Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 6 of 6

This is a discussion on BACK on a CGI clears form in the Shared & Semi-Dedicated forum
It seems weird to be one of very few who are posting here. But the responses have been great. So here goes for another one... ...

  1. #1
    Loyal Client
    Join Date
    Aug 2002
    Posts
    269

    BACK on a CGI clears form

    It seems weird to be one of very few who are posting here. But the responses have been great. So here goes for another one...

    I have an HTML page with just a teensy bit of PHP code in the beginning. In this HTML is a form which sends to a Perl script. If all the data sent to the Perl script is not right (i.e. a field was left blank), I print out "Error. Field missing data. Click BACK on your browser and correct". But when they do, the entire form is erased. Almost like the page was refreshed.

    Is there a way to retain what was entered instead of having that form screen cleared out? Is it the PHP that is doing it?

    For what its worth, the PHP code is from PhpSecurePages to enable protection for this private area:

    <?PHP $cfgProgDir = 'phpSecurePages/';
    include($cfgProgDir . "secure.php");
    ?>


    Thanks

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    I've seen this many times before, but I'm not exactly sure what causes it. It may be a cache issue. For example, if PhpSecurePages (or you for that matter) set any of the cache contol/no cache headers on your page, the browser isn't keeping a copy of the page when you submit the form, so when you click back the browser actually goes out and downloads the page again, sans the data you entered in the form, of course.

    Personally, I consider it bad form to make the user use any of the browser navigation buttons. I always provide an easy way for the user to go "back" (such as to the home page of my site). If I reject a form, I redraw the form again, with everything they entered and show them specifically what's wrong/missing. If you build your site from templates this is very easy to do. Even if you don't, it still isn't too difficult.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Loyal Client
    Join Date
    Aug 2002
    Posts
    269
    Thanks for the tip. If I knew how to draw the form again (I only know Perl and HTML), I'd do it. Can you guide me in a direction where I can learn something like that?

    Thanks again

    Sam

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    In the most straight forward way to do this is to modify your perl script to output a form instead of the message that says to hit the back button. Basically, copy the HTML of the form in your HTML file and paste it into the perl script (modifying it as necessary, of course. Then just add value="" attributes to each of the fields and fill them with the values that were originally submitted, and add a message in there somewhere that tells the person what went wrong.

    A better way to do this is with a template. I use patTemplate (http://www.php-tools.de), which is a PHP template processor. I use a hidden sub template where I can put the error message if needed, but the first time a person sees the form, its hidden. That way, if I change the form, I only have to change it in one place. There are probably some template engines for perl out there, too, but I'm not familiar with them.

    Templates can help a lot when you have a large site to maintain, but they also throw something new to learn at you. If your site is simple and your form isn't going to change, the first example is probably going to be the easiest thing for you to do.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  5. #5
    Loyal Client
    Join Date
    Aug 2002
    Posts
    269
    Great! Thanks for the help. So I'm basically duplicating the HTML form in the Perl script, and then maybe pointing the form tag so it is in a sense calling itself?

    I'll give it a try. Thanks again.

  6. #6
    Loyal Client
    Join Date
    Sep 2001
    Location
    Wichita, KS
    Posts
    1,647
    Yes, just print out the form again (keep EVERYTHING the same except add the value things)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •